-2

我正在尝试异步加载 Web 数据。我知道我可以使用以下内容,但我不知道如何调用 void(load) 方法。我怎么称呼这个?它似乎没有被自动调用。谢谢!

- (void)load
{
NSURL *myURL = [NSURL URLWithString:[NSString 
stringWithFormat:@"http://www.website.com"]];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:myURL 
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60];

[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
4

2 回答 2

1

就像 H2CO3 说的,你应该使用 [self load] 来调用该方法。我希望您想在方法 -(void)viewDidLoad 中调用它。在加载视图时调用一次。

于 2013-02-23T11:01:24.530 回答
0
__attribute__((constructor)) 
- (void)load
{
NSURL *myURL = [NSURL URLWithString:[NSString 
stringWithFormat:@"http://www.website.com"]];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:myURL 
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60];

[[NSURLConnection alloc] initWithRequest:request delegate:self];
}  

它在加载共享库时运行,通常是在程序启动期间。

看看__attribute__((constructor)) 究竟是如何工作的?

于 2013-02-23T11:09:20.670 回答