我在修改线程内的视图时遇到问题。我试图添加一个子视图,但是显示大约需要6秒钟或更长时间。我终于使它工作了,但我不知道它到底是怎么做到的。所以我想知道为什么它起作用以及以下方法之间的区别是什么:
//this worked -added the view instantly
dispatch_async(dispatch_get_main_queue(), ^{
//some UI methods ej
[view addSubview: otherView];
}
//this took around 6 or more seconds to display
[viewController performSelectorOnMainThread:@selector(methodThatAddsSubview:) withObject:otherView
waitUntilDone:NO];
//Also didnt work: NSNotification methods - took also around 6 seconds to display
//the observer was in the viewController I wanted to modify
//paired to a method to add a subview.
[[NSNotificationCenter defaultCenter] postNotificationName:
@"notification-identifier" object:object];
作为参考,在ACAccountStore类的完成处理程序内部调用了该方法。
accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
if(granted) {
//my methods were here
}
}
编辑:当我说它不起作用时,我的意思是花了大约6秒钟才能显示我添加的视图。
RISEBY
小唯快跑啊
泛舟湖上清波郎朗