【发布时间】:2013-12-11 16:00:48
【问题描述】:
我是一名高中生。我也完全是编码新手,我有一个简短的课程,我选择尝试为我的学校创建一个应用程序。我的大部分编码都成功了,但是我遇到了预期标识符或“(”的连续错误。我在互联网上搜索过,我还没有找到清除错误的方法。
所以,我已经完成了两个单独的代码,现在正尝试将它们复制并粘贴在一起。并且出现同样的错误。
错误:预期标识符或'('
@interface ViewController()
<UIWebViewDelegate>
@end
@implementation ViewController
@synthesize webView;
- (void)viewDidLoad
{
[super viewDidLoad];
webView.delegate = self;
NSURL *url = [NSURL URLWithString:@"https://twitter.com/u_bett"];
NSURLRequest *urlrequest = [NSURLRequest requestWithURL:url];
[webView loadRequest:urlrequest];
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if(navigationType == UIWebViewNavigationTypeLinkClicked)
{
return NO;
}
return YES;
}
{ //exected identifier or '('
[self.ScrollView setScrollEnabled: YES];
[self.ScrollView setContentSize: CGSizeMake(320, 900)];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)Twitter:(id)sender {NSURL *myURL = [NSURL URLWithString:@"https://twitter.com/u_bett"];
NSURLRequest *myRequest = [NSURLRequest requestWithURL:myURL];
[webView loadRequest:myRequest];
}
- (IBAction)Facebook:(id)sender {
NSURL *myURL = [NSURL URLWithString:@"https://www.facebook.com/BettSchools"];
NSURLRequest *myRequest = [NSURLRequest requestWithURL:myURL];
[webView loadRequest:myRequest]; }
编辑: 我按照你说的做了,它在代码的 BOOL 部分给了我几个错误。如下所示。 }
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
//Expected ';' after expression
//use of undeclared identifier 'request'
{
if(navigationType == UIWebViewNavigationTypeLinkClicked)
{
return NO;
}
return YES;
}
【问题讨论】:
-
另外,缩进你的代码。这是一个无法阅读的混乱。
-
Ctrl-I 在代码块上缩进。
-
@woz 因为这是一个可怕的误解。我已经在没有 Xcode 的情况下编写了 3 年的 Objective-C 代码。 (这尤其令人不安,因为无法区分 IDE 和编译器的人通常也完全不知道自己在用它们做什么,因此他们发布了低-质量,重复,琐碎的问题,例如这个,完全缺乏研究和努力。)
-
@H2CO3 虽然我同意你的观点 - 我注意到你可能对它有点苛刻,有时向用户解释为什么不应该使用它会使每个人都受益。问这个问题的人是因为他们会理解为什么他们不应该使用它以及学习一些东西,这将使您受益,因为您不必编辑或抱怨它。你不觉得吗?
-
当你甚至无法编译它,更不用说测试它时,你是如何“成功完成大部分编码的”?
标签: objective-c uiwebview uiscrollview