sub*_*ero 7 iphone objective-c iphone-sdk-3.0
我想在后台线程中运行一个方法,第一个方法将在几秒钟后在同一个(后台)线程上运行另一个方法.我写了这个:
- (IBAction)lauch:(id)sender
{
[self performSelectorInBackground:@selector(first) withObject:nil];
}
-(void) second {
printf("second\n");
}
-(void) first {
NSAutoreleasePool *apool = [[NSAutoreleasePool alloc] init];
printf("first\n");
[self performSelector:@selector(second) withObject:nil afterDelay:3];
printf("ok\n");
[apool release];
}
Run Code Online (Sandbox Code Playgroud)
但第二种方法从未被调用,为什么?而且,我怎么可以实现我的目标?
谢谢
你必须有一个runningSelector的运行循环:withObject:afterDelay:工作.
您的代码执行,first并在first退出时,线程消失.您需要运行一个运行循环.
加:
[[NSRunLoop currentRunLoop] run];
Run Code Online (Sandbox Code Playgroud)
到最后first.
| 归档时间: |
|
| 查看次数: |
3802 次 |
| 最近记录: |