2015-07-13 60 views
-1

我們使用的是當連接到主​​視圖控制器發送通知一些藍牙通信,我們得到它的通知,:更新UIButton邊框顏色會延遲?

- (void) receiveBLENotification:(NSNotification *) notification 
{ 

    if ([[notification name] isEqualToString:@"bluetooth"]) 
    { 
     //here we log the title right on time but the next will happen only after a while 
     NSLog(@"!!!!!!!"); 
    l1.layer.borderColor=[Globals sharedGlobals].mainColor.CGColor; 
    l2.layer.borderColor=[Globals sharedGlobals].mainColor.CGColor; 

所以,出於某種原因,顏色改變,但我們得到的日誌6秒後。

有沒有辦法強制它改變?

+0

是這6秒內凍結整個UI? – streem

+0

這段時間我不能更新任何UI元素。 – Curnelious

+0

這意味着主線程正忙,只有在完成後纔會更新UI。當你收到你的通知時,你會執行任何沉重的操作嗎? – streem

回答

0

解決了這一點:

dispatch_async(dispatch_get_main_queue(), ^{ 
       //here you update all required ui 
      });