关于NSThred开启多线程的方法

- (void)performSelectorInBackground:(SEL)aSelector withObject:(id)arg

[self performSelectorInBackground:@selector(doSomething) withObject:nil];

这个方法是开启另一个线程,在 doSomething 方法中用于处理耗时的操作

当需要UI刷新处理的时候要回到主线程:

- (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg waitUntilDone:(BOOL)wait;

// UI刷新
    [self performSelectorOnMainThread:@selector(refreshUI) withObject:nil waitUntilDone:NO];

或者

// UI刷新
    dispatch_async(dispatch_get_main_queue(), ^{
        NSLog(@"refreshUI");
    });

 

posted on 2016-06-21 18:24  xiao孛  阅读(491)  评论(0编辑  收藏  举报