xcode中的预期标识符] [英] expected Identifier ] in xcode
问题描述
我决定对一个iPhone应用程序进行编程,以了解它的简易性.除了这部分,我已经完成了大部分编码,请帮忙:
I decided to program an iphone app to see how easy it was. I have finalized most of the coding except this part, please help:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
//1
NSString *urlString = @"http://zaphod_beeblebrox.pythonanywhere.com/";
//2
NSURL *url = [NSURL URLWithString:urlString];
//3
NSURLRequest *request = [NSURLRequest requestWithURL:url];
//4
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
//5
[NSURLConnection sendAsynchronousRequest:request queue:queue
completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
if ([data length] > 0 && error == nil) [UIWebView]
else if (error != nil) NSLog(@"Error: %@", error);
}];
}
@end
推荐答案
错误消息的来源是您当前拥有[UIWebView]
,这没有任何意义,因为方括号表示您正在调用方法,但是您有一个类名,但没有任何方法名.目前尚不清楚您要做什么.请参阅对象消息传递"部分,介绍了调用对象方法(即,向对象发送消息).
The source of your error message is that you currently have [UIWebView]
, which makes no sense because the square brackets designate that you're invoking a method, but you have a class name, but you don't have any method name. It's not clear what you're trying to do. See the Object Messaging section of the Objective-C Programming Language, which talks about invoking object methods (i.e. sending the object a message).
我猜您正在尝试在UIWebView
中加载html页面?显然,您的UIWebView
需要一个IBOutlet
. (如果这没有意义,我建议您从Apple的教程
I'm guessing you're trying to load a html page in a UIWebView
? You obviously need an IBOutlet
for your UIWebView
. (If that doesn't make sense, I'd suggest you start with Apple's tutorial Your First iOS App.)
在下面的示例中,我假设您的IBOutlet
被称为webview
,因此我可能建议您摆脱NSOperationQueue
和NSUrlConnection
并让UIWebView
加载html为您:
In my example below, I'm going to assume your IBOutlet
is called webview
, and thus I might advise getting rid of the NSOperationQueue
and NSUrlConnection
and just have the UIWebView
load the html for you:
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *urlString = @"http://zaphod_beeblebrox.pythonanywhere.com/";
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.webview loadRequest:request];
}
也许值得阅读一些iPhone编程教程(只需在Google上搜索它,您将获得大量点击量),或者看看Apple http://developer.apple.com .
It might be worth going through a few iPhone programming tutorials (just google it and you'll get tons of hits), too or look at the Apple App Programming Guide or check out the wonderful resources at http://developer.apple.com.
这篇关于xcode中的预期标识符]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!