스레드 충돌에서 nspathcontrol 객체를 호출합니다
-
22-07-2019 - |
문제
어떤 이유로 스레드에서 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];
}
해결책
"충돌"은 특정 도움을 제공 할만 큼 설명 할만 큼 충분히 설명하지 않지만 클래스가 스레드 안전으로 나열되지 않으면 아마도 그렇지 않을 것입니다.
UI 요소는 일반적으로 기본 스레드에서만 업데이트되어야합니다.
제휴하지 않습니다 StackOverflow