1
//display&data _myview.view_searchbar.btn_back.hidden=true; [LSJsonHelper PrintLog:@"viewdidload"]; [LSJsonHelper RequestHttp:gbl_urlindexcategory handle:^(NSDictionary *data) { [LSJsonHelper PrintLog:@"callback"]; _data_category=[LSJsonHelper ConverJason2Model:data cc:[LSModel_VCategory_All class] isArray:YES]; NSString *img1=[NSString stringWithFormat:@"%@%@",gbl_imgspath,_data_category[0].cg_pic]; [LSJsonHelper PrintLog:@"before request img"]; dispatch_async(dispatch_get_main_queue(), ^{ [LSNSURL LoadImageForimg:img1 img:_myview.image_eat]; [LSJsonHelper PrintLog:@"after set img to imagevie"]; }); [LSJsonHelper PrintLog:@"end this function"]; }];
2018-07-02 17:22:12.302 MyCity100[3014:82518] 2018-07-02 05:22:12:301.<NSThread: 0x7b771880>{number = 1, name = main} :viewdidload 2018-07-02 17:22:12.309 MyCity100[3014:82518] 2018-07-02 05:22:12:309.<NSThread: 0x7b771880>{number = 1, name = main} :viewWillAppear 2018-07-02 17:22:12.354 MyCity100[3014:82518] 2018-07-02 05:22:12:355.<NSThread: 0x7b771880>{number = 1, name = main} :viewDidAppear 2018-07-02 17:22:12.431 MyCity100[3014:82573] 2018-07-02 05:22:12:431.<NSThread: 0x7c98ed90>{number = 3, name = (null)} :callback 2018-07-02 17:22:12.436 MyCity100[3014:82573] 2018-07-02 05:22:12:436.<NSThread: 0x7c98ed90>{number = 3, name = (null)} :before request img 2018-07-02 17:22:12.437 MyCity100[3014:82573] 2018-07-02 05:22:12:437.<NSThread: 0x7c98ed90>{number = 3, name = (null)} :end this function 2018-07-02 17:22:15.616 MyCity100[3014:82518] 2018-07-02 05:22:15:616.<NSThread: 0x7b771880>{number = 1, name = main} :after set img to imagevie
可以看到。异步网络请求后的回调函数是在子线程中执行。
所以时间上一般页面执行完了显示函数,才会执行回调。
更主要的是页面上的控件都是在主线程上创建的。基本所有语言都是要求由主线程进行刷新。
oc 也不例外,所以编写主线程的回调函数。
dispatch_async(dispatch_get_main_queue(), ^{