2014-02-24 170 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]; 
} 

因为这是实现代码不应该在界面上。