iPhone NSThread 帮助

发布于 2024-12-02 17:32:05 字数 798 浏览 3 评论 0原文

我的线程遇到一些问题。目前,由 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

任性一次 2024-12-09 17:32:05

请尝试在“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.

风尘浪孓 2024-12-09 17:32:05

我认为你应该学习一些 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文