如果我得到你的权利,你可以把这些语句的方法,并呼吁performSelectorInBackground
:
(void)asyncMethod {
NSString *care = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://localhost/untitled.txt"]];
if (care == @"ONRED") { //untitled.txt = ONRED
[red_on setHidden:NO];
[red_off setHidden:YES];
}
}
// in some other method
[self performSelectorInBackground:@selector(asyncMethod) withObject:nil];
另一种选择是使用大中央调度(如this answer描述):
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,
(unsigned long)NULL), ^(void) {
NSString *care = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://localhost/untitled.txt"]];
if (care == @"ONRED") { //untitled.txt = ONRED
[red_on setHidden:NO];
[red_off setHidden:YES];
}
});
什么是循环? – MByD 2012-03-09 09:48:30
我不是。有没有可能异常地运行虚空? – theShay 2012-03-09 11:11:58