国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS NSThreadGCD 線程與隊列(一)

2019-11-06 09:43:18
字體:
來源:轉載
供稿:網友
////  NSThreadVController.m//  ZM_NSThreadGCD////  Created by ZM on 2015/2/9.//  Copyright ? 2015年ZM. All rights reserved.//#import"NSThreadVController.h"@interfaceNSThreadVController (){    UILabel *my_label;}@end@implementationNSThreadVController- (void)viewDidLoad{    [superviewDidLoad];    self.title= @"NSThreadVC";    my_label= [[UILabelalloc]initWithFrame:CGRectMake(80,80,150,60)];    my_label.backgroundColor=[UIColorcyanColor];    my_label.text=@"幸福每一天";    my_label.font=[UIFontsystemFontOfSize:15];    my_label.textAlignment=NSTextAlignmentCenter;    [self.viewaddSubview:my_label];       [selfaddBtnTitle:@"開辟分線程"frame:CGRectMake(10, 200,200,35)Tag:111];}- (void)myBtnClick:(UIButton*)Btn{       NSDictionary *params = @{@"key1":@"value1",                             @"key2":@"value2"};    //開辟分線程    [NSThreaddetachNewThreadSelector:@selector(newThread:)toTarget:selfwithObject:params];}//分線程-(void)newThread:(NSMutableDictionary*)dic{    //創建線程    //判斷BOOL量    NSThread *thread = [NSThreadcurrentThread];    BOOL isMainThread = [threadisMainThread];       NSLog(@"---> thread = %d",isMainThread);    NSLog(@"---> dic = %@ /n ",dic);    //創建主線程    //去網絡請求獲取數據請求完成 必須要回到主線程刷新數據    [selfperformSelectorOnMainThread:@selector(mainThread:)withObject:@"在主線程刷新數據"waitUntilDone:YES];      //    //1.直接在開辟的線程中可以刷新數據//    my_label.text = [dic objectForKey:@"key1"];////    //2.無論在分線程或者主線程中再開辟一個分線程:都不能刷新數據//    [NSThread detachNewThreadSelector:@selector(againNewThread_Two:) toTarget:self withObject:@{@"labelText": @"label"} ];      }//主線程-(void)mainThread:(NSString*)str{    //1.主線程刷新數據    NSLog(@"---> str: %@",str);    my_label.text= str;          //2.無論在分線程或者主線程中再開辟一個分線程:都不能刷新數據//    [NSThread detachNewThreadSelector:@selector(againNewThread_Two:) toTarget:self withObject:@{@"labelText": @"label"} ];   }//在線程中:再開辟一個分線程-(void)againNewThread_Two:(NSMutableDictionary*)dic{    NSString *str= [dic objectForKey:@"label"];    NSLog(@"---> my_label.text: %@ /n ",str);    my_label.text= str;}@end
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 榆中县| 新郑市| 汕头市| 永嘉县| 邹城市| 四川省| 板桥市| 莒南县| 浑源县| 福贡县| 巴彦淖尔市| 桑植县| 蒲江县| 无极县| 阿瓦提县| 芜湖市| 东台市| 蕲春县| 罗平县| 平利县| 屯昌县| 寿光市| 吴江市| 奉化市| 莎车县| 湘乡市| 嵊泗县| 建平县| 奈曼旗| 永安市| 高要市| 青阳县| 澄江县| 四川省| 方城县| 广安市| 达拉特旗| 漠河县| 营口市| 瑞丽市| 新野县|