2011-11-06 37 views
-2

嗨我的 - 我的Xcode項目中的 - (void)有問題。所有在這裏 首先是代碼- (void)...不工作/上訴(iOS)

ViewController.h

#import <UIKit/UIKit.h> 

@interface ViewController : UIViewController { 
    IBOutlet UIWebView *webview; 
    IBOutlet UIActivityIndicatorView *active; 
    UIAlertView *alert_start; 
    UIAlertView *alert_error; 

} 



-(IBAction)tele_button:(id)sender; 
-(IBAction)mail_button:(id)sender; 
-(IBAction)web_button:(id)sender; 
-(IBAction)news_button:(id)sender; 


@end 

ViewController.m

#import "ViewController.h" 

@implementation ViewController 





- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Release any cached data, images, etc that aren't in use. 
} 

#pragma mark - View lifecycle 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 



    //Stop Bounce for WebView 
    for (id subview in webview.subviews) 
     if ([[subview class] isSubclassOfClass: [UIScrollView class]]) 
      ((UIScrollView *)subview).bounces = NO; 



    //First Start Alert 
    [alert_start show]; 
    NSLog(@"first alert"); 
    NSString *start_alert = [[NSUserDefaults standardUserDefaults] objectForKey:@"alert_start"]; 
    if(start_alert == nil) 
    { 
     [[NSUserDefaults standardUserDefaults] setValue:@"1" forKey:@"alert_start"]; 
     [[NSUserDefaults standardUserDefaults] synchronize]; 

     UIAlertView *alert_start = [[UIAlertView alloc] initWithTitle:@"iOptibelt" 
                   message:@"On some points this application need a internet connection." 
                  delegate:self 
                cancelButtonTitle:@"OK" 
                otherButtonTitles:nil]; 

     [alert_start show]; 
     [alert_start release]; 

    } 


// Do any additional setup after loading the view, typically from a nib. 
    [webview loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"home-de" ofType:@"html"]isDirectory:NO]]]; 
    NSLog(@"webview fertig"); 
} 

-(void)webViewDidStartLoad:(UIWebView *) webview { 
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; 
    [active startAnimating]; 
    NSLog(@"lade"); 
} 
-(void)webViewDidFinishLoad:(UIWebView *) webview { 
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; 
    [active stopAnimating]; 
    NSLog(@"fertig"); 

} 

-(void)webView: (UIWebView *) webview didFailLoadWithError:(NSError *)error{ 
    NSLog(@"lade error");  
    UIAlertView *alert_error = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Can't connect. Please check your internet Connection" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
    [alert_error show]; 
    [alert_error release]; 

}; 


- (IBAction)tele_button:(id)sender{ 
    NSLog(@"it's connected!");   
    //Local HTML Call Button 
    NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"phone" ofType:@"html"]isDirectory:NO]]; 
    [webview loadRequest:theRequest]; 
} 


- (IBAction)mail_button:(id)sender{ 
    NSLog(@"it's connected!"); 
    //Mail App Mail Button 
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://[email protected]"]]; 
} 
- (IBAction)web_button:(id)sender{ 
    NSLog(@"it's connected!"); 
    //Local HTML Button 
    NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString: @"http://optibelt.com"]]; 
    [webview loadRequest:theRequest]; 
} 

- (IBAction)news_button:(id)sender{ 
    NSLog(@"it's connected!"); 
    //local Home Button 
    NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"home-de" ofType:@"html"]isDirectory:NO]]; 
    [webview loadRequest:theRequest]; 
} 


- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 

- (void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 
} 

- (void)viewDidAppear:(BOOL)animated 
{ 
    [super viewDidAppear:animated]; 
} 

- (void)viewWillDisappear:(BOOL)animated 
{ 
    [super viewWillDisappear:animated]; 
} 

- (void)viewDidDisappear:(BOOL)animated 
{ 
    [super viewDidDisappear:animated]; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); 
} 

@end 

最後我的3 - (空)不工作,我已經沒有更多的想法可能是什麼問題....

-(void)webViewDidStartLoad:(UIWebView *) webview { 
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; 
    [active startAnimating]; 
    NSLog(@"lade"); 
} 
-(void)webViewDidFinishLoad:(UIWebView *) webview { 
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; 
    [active stopAnimating]; 
    NSLog(@"fertig"); 

} 

-(void)webView: (UIWebView *) webview didFailLoadWithError:(NSError *)error{ 
    NSLog(@"lade error");  
    UIAlertView *alert_error = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Can't connect. Please check your internet Connection" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
    [alert_error show]; 
    [alert_error release]; 
+6

討厭它,當我寫C++和我的'int'不起作用。 –

回答

0

你需要設置這一行代碼

webView.delegate = self; 

也許在您的viewDidLoad方法

0

以你粘貼代碼,你有直譯和總代碼,這個問題是一個語法錯誤。您第一次粘貼郵件時,在關閉}後面有一個分號,不應該在那裏。第二次,你錯過了關閉},應該在那裏。該代碼應該是:

-(void)webView:(UIWebView *)webview didFailLoadWithError:(NSError *)error { 
    NSLog(@"lade error");  
    UIAlertView *alert_error = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Can't connect. Please check your internet Connection" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
    [alert_error show]; 
    [alert_error release]; 
} 
0

我必須先說,你的問題寫得很差,從我的理解你的webView方法不工作。

您需要將您的webView delegate設置爲Bobj-C提及。

webView.delegate = self; 

其次,你需要添加UIWebViewDelegate到你的頭文件(.h)中

@interface ViewController : UIViewController <UIWebViewDelegate> { 
} 

也;可能重複:iPhone - webViewDidFinishLoad not called

0

@jrturton的答案後,你說UIWebviewDelegate的方法被調用,但隨後

是...好固定的loadingViews ...只是錯誤警報不起作用......再

如果Error aler是在代碼中alert_start UIAlertView中,這可能是因爲你的第一次顯示alert_start後更新[NSUserDefaults standardUserDefaults]

如果Error alertalert_error UIAlertView中,jrturton是正確的,你需要確保你的UIWebView無法加載指定的文件:你很幸運,你使用的目的C.我

[webview loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"home-de" ofType:@"html"]isDirectory:NO]]];