2012-10-15 8 views
6

वर्तमान में मैं UIWebView का उपयोग करके आईओएस के लिए एक ऐप प्रोग्रामिंग कर रहा हूं। मेरा लक्ष्य वेबव्यू का उपयोग करके एक PHP साइट (मेरे वेबसर्वर से) प्रदर्शित करना है। मैं एचटीएमएल, सीएसएस, जेएस और PHP के साथ बहुत अच्छा हूं लेकिन ऑब्जेक्ट सी मेरी ताकत नहीं है। हालांकि, मैं सब कुछ लागू करने में कामयाब रहा हूं और मेरा लक्ष्य अब है (जब आईओएस इंटरनेट कनेक्शन नहीं है) त्रुटि चेतावनी के बाद सर्वर पर फ़ाइल के बजाय स्थानीय फ़ाइल प्रदर्शित करने के लिए। Google का उपयोग करने के बाद मैं इसे स्वतंत्र रूप से करने में कामयाब रहा, लेकिन फॉलबैक के रूप में नहीं।एक्सकोड और वेब व्यू: यदि कोई इंटरनेट कनेक्शन नहीं है तो स्थानीय एचटीएमएल लोड करें (फॉलबैक)

अभी यह अलर्ट प्रदर्शित करता है, लेकिन एक टैप के बाद ठीक है उपयोगकर्ता को एक खाली पृष्ठ मिलता है। बहुत उपयोगकर्ता के अनुकूल नहीं :(स्थानीय एचटीएमएल फाइल में मैं एक प्रकार का "रीफ्रेश बटन" लागू कर सकता हूं। अगर आपके पास (बेहतर?) समाधान है तो मैं बहुत खुश हूं। धन्यवाद!

मेरा सिस्टम: एक्सकोड 4.5। ओएस पर 1 एक्स 10.8.2

ViewController.h

#import <UIKit/UIKit.h> 

@interface ViewController : UIViewController <UIWebViewDelegate> 
@property (strong, nonatomic) IBOutlet UIWebView *webView; 
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *loadingSign; 
- (void)loadSite; 

@end 

ViewController.m

#import "ViewController.h" 

@interface ViewController() 

@end 

@implementation ViewController 
@synthesize webView; 
@synthesize loadingSign; 

-(void) webViewDidStartLoad:(UIWebView *)webView { 
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; 
    [self.loadingSign startAnimating]; 
    self.loadingSign.hidden = NO; 
} 

-(void) webViewDidFinishLoad:(UIWebView *)webView { 
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; 
    [self.loadingSign stopAnimating]; 
    self.loadingSign.hidden = YES; 
} 

-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { 
    [self.loadingSign stopAnimating]; 
    self.loadingSign.hidden = YES; 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Keine Internetverbindung" message:@"Bitte verbinde dich mit dem Internet." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
    [alert show]; 
} 

- (void)loadSite 
{ 
    NSString *fullURL = @"http://website.com"; 
    NSURL *url = [NSURL URLWithString:fullURL]; 
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; 
    [webView loadRequest:requestObj]; 
    webView.scrollView.bounces = NO; 
    webView.delegate = self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    [self loadSite]; 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

@end 
+0

लोड स्थानीय एचटीएमएल जब त्रुटि होता है से (आप क्यों त्रुटि है जांच करने की आवश्यकता) - (शून्य) वेबदृश्य::

मैं इस का मतलब (UIWebView *) WebView didFailLoadWithError: (NSError *) त्रुटि – Vjy

उत्तर

2

आप निम्न UIAlertViewDelegate विधि को लागू कर सकते हैं:

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex 

इस विधि को तब कहा जाता है जब अलर्ट व्यू को उसके शरीर में खारिज कर दिया जाता है, तो आप अपने स्थानीय संसाधनों को फॉलबैक के रूप में लोड कर सकते हैं।

अपने ViewController के इंटरफेस में

आप जोड़ना चाहिए:

@interface ViewController : UIViewController <UIWebViewDelegate,UIAlertViewDelegate> 

और जब आप alloc अपने alertView आत्म करने के लिए प्रतिनिधि निर्धारित किया है।

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Keine Internetverbindung" message:@"Bitte verbinde dich mit dem Internet." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
+0

आपके त्वरित समाधान के लिए धन्यवाद। यह पूरी तरह से काम करता है। लेकिन मैं आपका आखिरी वाक्यांश नहीं समझता ... – ohh2ahh

संबंधित मुद्दे