在线程崩溃中调用NSPathControl对象

时间:2009-10-30 16:03:01

标签: objective-c crash multithreading

由于某种原因,在线程中调用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];
}

1 个答案:

答案 0 :(得分:1)

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

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

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

相关问题