2011-11-06 52 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]]];