【问题标题】:Calling NSPathControl object in thread crashes在线程崩溃中调用 NSPathControl 对象
【发布时间】:2009-10-30 16:03:00
【问题描述】:

由于某种原因,在线程中调用 NSPathControl 对象会导致崩溃。

- (IBAction) action5:(id)sender {
 [outlet_NSPathControl1 setURL: [NSURL fileURLWithPath: @"/Users/admin/"]]; // Works fine here
 [self performSelectorInBackground:@selector(background1) withObject:self]; // Jump to the thread
}

-(void) background1 {
 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 [outlet_NSButton1 setTitle: [NSString stringWithFormat: @"%d", index]];
 [outlet_NSPathControl1 setURL:[NSURL fileURLWithPath: @"/Users/admin/"]]; // Crashes here
 [pool drain];
}

【问题讨论】:

    标签: objective-c crash multithreading


    【解决方案1】:

    “崩溃”的描述性不足以提供任何具体的帮助,但如果一个类没有被列为线程安全的,那么它可能不是。

    http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Multithreading/ThreadSafetySummary/ThreadSafetySummary.html

    UI 元素通常也应该只从主线程更新。

    【讨论】:

    • 感谢您提供的信息。你可能知道,我是 Mac 编程新手。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-25
    • 1970-01-01
    相关资源
    最近更新 更多