NSNotification은 주 스레드가 아닌 다른 스레드에서 해당 selector를 호출하기 때문에 UIViews 나 다른 인터페이스 요소에 대한 변경 사항 종종 효력을 발휘하기가 느립니다. 주 스레드가 바쁜 경우 (이것은 종종 광산입니다!) 가장 심각합니다.NSNotifications에 응답 할 때 UIViews를 업데이트하는 가장 좋은 방법은 무엇입니까
"performSelectorOnMainThread :"를 호출하여 문제를 해결할 수 있습니다. 이게 가장 좋은 방법인가요?
- (void) gotMovieSaveFinishNotication: (NSNotification *) not {
NSURL *exportMovieURL = (NSURL *) [not object];
//saving the composed video to the photos album
ALAssetsLibrary* library = [[[ALAssetsLibrary alloc] init] autorelease];
if(![library videoAtPathIsCompatibleWithSavedPhotosAlbum: exportMovieURL]) {
NSLog(@"videoAtPathIsCompatibleWithSavedPhotosAlbum fails for: @",exportMovieURL);
return;
}
[library writeVideoAtPathToSavedPhotosAlbum:exportMovieURL
completionBlock:^(NSURL *assetURL, NSError *error)
{
[self performSelectorOnMainThread:@selector(setTintToNormal)
withObject: NULL
waitUntilDone: YES];
if(error)
{
DLog(@"The video saving failed with the following error =============== %@",error);//notify of completion
}
else
{
DLog(@"The video is saved to the Photos Album successfully");
}
}];
}
메인 스레드에서 UIKit 액세스의 위험에 대해 상기 알림 주셔서 감사. 나는 전에 그것을 읽었지만 어떻게 든 진지하게 받아들이지 않았다 :-). 이제 나는 곧고 좁아졌다. –
예, 해당 카테고리 솔루션이 마음에 들었습니다. 특히 이것이 한 곳 이상에서 일어나고 있기 때문에 가장 복잡한 방법처럼 보입니다. 도와 주셔서 감사합니다! –