iPhone NSThread 帮助
我的线程遇到一些问题。目前,由 showInstructions
带来的视图在线程完成之前被禁用......如何在线程进行时使其具有交互性?
提前致谢!
[self performSelectorOnMainThread:@selector(loadEverything) withObject:self waitUntilDone:YES];
-(void)loadEverything {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[self performSelector:@selector(showInstructions)];
[self performSelector:@selector(loadStats)];
[self performSelector:@selector(animate_sideBTN)];
[self performSelector:@selector(loadNIBs)];
[self performSelector:@selector(incrementStats)];
[NSThread detachNewThreadSelector:@selector(loadMap) toTarget:self withObject:nil];
[[self.view viewWithTag: 123] removeFromSuperview];
[pool drain];
}
I'm having some problems with my thread. Currently, the view brought up by showInstructions
is disabled until the thread is done... how can I make it interactive while the thread is going on?
Thanks in advance!
[self performSelectorOnMainThread:@selector(loadEverything) withObject:self waitUntilDone:YES];
-(void)loadEverything {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[self performSelector:@selector(showInstructions)];
[self performSelector:@selector(loadStats)];
[self performSelector:@selector(animate_sideBTN)];
[self performSelector:@selector(loadNIBs)];
[self performSelector:@selector(incrementStats)];
[NSThread detachNewThreadSelector:@selector(loadMap) toTarget:self withObject:nil];
[[self.view viewWithTag: 123] removeFromSuperview];
[pool drain];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请尝试在“performSelectorOnMainThread”中调用 -(void)loadEverything ,并从该调用 [NSThread detachNewThreadSelector:] 进行不影响 UI 组件的操作,并从该调用 [self PerformSelector] 进行影响 UI 组件的操作。
Please try calling -(void)loadEverything in "performSelectorOnMainThread" and from that call [NSThread detachNewThreadSelector:] for operation which are not affecting UI components and [self performSelector] for which are affecting UI components.
我认为你应该学习一些 GCD 并在块内执行相同的代码。或者使用 NSOperation...如果可能的话避免线程。
I think you should learn some GCD and do the same code inside a block. Or use an NSOperation… Avoid threads if possible.