![](/img/trans.png)
[英]How to suppress the deprecation warning “dispatch_get_current_queue() is deprecated…in iOS 6.0”?
[英]Objective-C delay a method in iOS 6 dispatch_get_current_queue deprecated
我正在使用dispatch_after()
和dispatch_get_current_queue()
來延遲一個方法。 例如,延遲1秒:
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_current_queue(), ^{
[self someMethod];
});
由於在iOS 6中不推薦使用dispatch_get_current_queue()
,是否有任何其他等效的方法來執行此操作而不為performSelector:withObject:afterDelay:
創建另一個單獨的方法performSelector:withObject:afterDelay:
?
編輯:
來自Peter Segerblom的回答:
// Without updating UI
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSLog(@"Hello World");
});
// updating UI
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[imageView setBackgroundColor:[UIColor redColor]];
[self.view addSubview:imageView];
});
干杯!
我認為你應該使用dispatch_get_global_queue()
代替。 我認為它應該做同樣的事情。 如果您只想延遲該方法而不是在另一個que中運行,那么您可以使用dispatch_get_main_queue()
。 請記住,如果您不在主要問題中,則無法更新用戶界面。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.