dispatch_async

UITextView *text=[[UITextView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    [self.view addSubview:text];
    __block int count=0;
    //异步并行处理
    dispatch_async(dispatch_get_global_queue(0, 0), ^(){
        for (int i=0; i<100; i++) {
            usleep(10000);
           count=count+i;
        }
        //主线程更新界面
        dispatch_sync(dispatch_get_main_queue(), ^(){
            text.text=[NSString stringWithFormat:@"%d",count];
        });
    });

 

posted @ 2013-02-18 10:44  Ethan_村长  阅读(249)  评论(0编辑  收藏  举报