如果我得到你的權利,你可以把這些語句的方法,並呼籲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