NSThread的使用

//    1. 創建子線程
    [self performSelectorInBackground:<#(SEL)#> withObject:<#(id)#>];
    
//    2. 創建了一個新的子線程
    [NSThread detachNewThreadSelector:@selector(print) toTarget:self withObject:nil];
    
//    3. 通過創建NSThread對象的方式實現多線程
    NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(print) object:nil];
    [thread start];
    [thread cancel];
    
//    4. 繼承NSThread
    MyThread *thread = [[MyThread alloc] init];

[NSThread isMainThread] //判斷線程是否在主線程中

[self performSelectorOnMainThread:@selector(download:) withObject:data waitUntilDone:YES];//切換到主線程中


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章