美文网首页
线程中处理 UI 需要注意

线程中处理 UI 需要注意

作者: 失忆的程序员 | 来源:发表于2021-07-16 11:33 被阅读0次
    -[UILabel setText:] must be used from main thread only
    
    
    解决方法:
    
        [self performSelectorOnMainThread:@selector(<#selector#>:)     withObject:<#你要处理的数据#> waitUntilDone:YES];
    
    
    - (void)<#selector#>:(<#你要处理的数据#> *)<#name#>
    {
    }
    
    
    
        [self performSelector:action withObject:obj afterDelay:0.3];
    
    
    
    dispatch_async(dispatch_get_global_queue(0, 0), ^{ 
        // 处理耗时操作的代码块... 
        // 通知主线程刷新 
        dispatch_async(dispatch_get_main_queue(), ^{ 
        //回调或者说是通知主线程刷新, 
        }); 
    });
    
    
            dispatch_semaphore_t sem = dispatch_semaphore_create(0);
            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                XPFLog(@"任务一:");
                
            });
            
            dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                XPFLog(@"任务二:");
                
            });
            
            dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                XPFLog(@"任务三:");
                dispatch_semaphore_signal(sem);
                
            });
    

    相关文章

      网友评论

          本文标题:线程中处理 UI 需要注意

          本文链接:https://www.haomeiwen.com/subject/hkzvpltx.html