2014-02-24 133 views
-3

我正在使用網絡瀏覽器應用程序,但目前我陷入錯誤:「預期的標識符或'('',我不知道該怎麼辦。顯示錯誤:預期標識符或(

{:here is the error 
    NSURL *url = [NSURL URLWithString:urlString]; 
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url]; 
    [self.webView loadRequest:urlRequest]; 
} 

幫助表示讚賞

更新:

我不知道我應該什麼其他的代碼給你所以這裏是在ViewController.m整個代碼文件:

#import "ViewController.h" 

@interface ViewController() 
@property (weak, nonatomic) IBOutlet UIWebView *webView; 
@property (weak, nonatomic) IBOutlet UIBarButtonItem *back; 
@property (weak, nonatomic) IBOutlet UIBarButtonItem *refresh; 
@property (weak, nonatomic) IBOutlet UIBarButtonItem *stop; 
@property (weak, nonatomic) IBOutlet UIBarButtonItem *forward; 

- (void)loadRequestFromString:(NSString*)urlString; 

{ *HERE IS THE ERROR:EXPECTED IDENTIFIER OR '('* 
    NSURL *url = [NSURL URLWithString:urlString]; 
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url]; 
    [self.webView loadRequest:urlRequest]; 
} 

@end 

@implementation ViewController ***HERE IS A WARNING SAYING:METHOD DEFINITION FOR 'LOADREQUESTFROMSTRING:'NOT FOUND*** 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any `enter code here`additional setup after loading the view, typically from a nib. 
    [self loadRequestFromString:@"http://www.apple.com/startpage/"]; 
} 

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

@end 
+0

該錯誤顯示在哪裏? – Flexicoder

+1

顯示更多代碼(上下文),因爲您發佈的代碼沒有任何問題。 – trojanfoe

回答

1

爲什麼你要執行的代碼在你的界面

@interface ViewController() 
@property (weak, nonatomic) IBOutlet UIWebView *webView; 
@property (weak, nonatomic) IBOutlet UIBarButtonItem *back; 
@property (weak, nonatomic) IBOutlet UIBarButtonItem *refresh; 
@property (weak, nonatomic) IBOutlet UIBarButtonItem *stop; 
@property (weak, nonatomic) IBOutlet UIBarButtonItem *forward; 

// This is a private interface and doesn't need the below line ever. 
// If you want this public then add it to the interface in the .h file. 
- (void)loadRequestFromString:(NSString*)urlString; 

***************************************************************************** 
// This is implementation code and shouldn't be here. 
// This belongs in the implementation not the interface 
{ *HERE IS THE ERROR:EXPECTED IDENTIFIER OR '('* 
    NSURL *url = [NSURL URLWithString:urlString]; 
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url]; 
    [self.webView loadRequest:urlRequest]; 
} 
***************************************************************************** 
@end 

在您的實現@implementation添加

@implementation ViewController 
// Your other code such as viewDidLoad etc 

// Adding this method to the implementation will also get rid of the warning 
// ***HERE IS A WARNING SAYING:METHOD DEFINITION FOR 'LOADREQUESTFROMSTRING:'NOT FOUND*** 
// As it will now be implemented but there is no reason to declare the method in a private interface 
- (void)loadRequestFromString:(NSString*)urlString; 
{ 
    NSURL *url = [NSURL URLWithString:urlString]; 
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url]; 
    [self.webView loadRequest:urlRequest]; 
} 

因爲這是實現代碼不應該在界面上。