ios - Using GCD in performSelectorInBackground: , How this action get an exception? -


when call "performselectorinbackground" process action asynchronously.

my code struct like:

[self performselectorinbackground:@selector(addtheadditionaldatasourcetotableview) withobject:nil]; 

and addtheadditionaldatasourcetotableview's code struct :

-(void)addtheadditionaldatasourcetotableview {     dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_high, 0), ^{     ...         dispatch_async(dispatch_get_current_queue(), ^{         ...         });     ...     }); } 

and after viewcontroller call 'popviewcontroller', dealloc never called!!!

i know can call 'addtheadditionaldatasourcetotableview' directly. process asynchronously , works fine. dealloc called when viewcontroller did disappear.but don't know why calling using "performselectorinbackground" cause exception above.

: (

- (void)reloadtableviewdatasource {     //  should calling tableviews data source model reload     //  put here demo     [self performselectorinbackground:@selector(refreshtableview) withobject:nil];     //[self refreshtableview];  }  - (void)refreshtableview {  nsstring *mypoint = [self currentlocationpoint]; if (!mypoint || [mypoint isequaltostring:@""]) {     [self enablebuttons];     [tableview tableviewdidfinishedloading];     return; }  interface *interface = [[interface alloc]init]; /* 默认从page 1开始刷新数据 */ [self disablebuttons];  _interface = (id)interface; interface.delegate = self; dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_high, 0), ^{     [interface aroundinfofromserviceinterface:_distancetype                                 withtabletype:_tabletype                                  withsorttype:_sorttype                                   withpagenum:1                                withnumperpage:numberofcellinonerequest withpoint:mypoint]; }); //[interface release]; //[tableview flashmessage:@"hahahah"]; }  - (void)aroundinfofromserviceinterface:(nsinteger)distance                      withtabletype:(nsinteger)tabletype                       withsorttype:(nsinteger)sorttype                        withpagenum:(nsinteger)pagenum                     withnumperpage:(nsinteger)numperpage                          withpoint:(nsstring *)mypiont {  requestdata *data1 = [requestdata requestdata:[nsstring stringwithformat:@"%d", distance] key:@"arounddistant"]; requestdata *data2 = [requestdata requestdata:[nsstring stringwithformat:@"%d", tabletype] key:@"itemtype"]; requestdata *data3 = [requestdata requestdata:[nsstring stringwithformat:@"%d", sorttype] key:@"sorttype"]; requestdata *data4 = [requestdata requestdata:[nsstring stringwithformat:@"%d", pagenum] key:@"pagenum"]; requestdata *data5 = [requestdata requestdata:[nsstring stringwithformat:@"%d", numperpage] key:@"numperpage"]; requestdata *data6 = [requestdata requestdata:[nsstring stringwithformat:@"%@", mypiont] key:@"mappoint"]; nslog(@"%@ , %@ , %@ , %@ , %@ , %@" , [nsstring stringwithformat:@"%d", distance] ,[nsstring stringwithformat:@"%d", tabletype] ,[nsstring stringwithformat:@"%d", sorttype] ,  [nsstring stringwithformat:@"%d", pagenum], [nsstring stringwithformat:@"%d", numperpage] , [nsstring stringwithformat:@"%@", mypiont]); nsarray *temparray = [nsarray arraywithobjects:data1, data2, data3, data4, data5, data6, nil];  datafromservice *datafromservice = [[[datafromservice alloc]init]autorelease];  dispatch_async(dispatch_get_main_queue(), ^{      nsstring *strcontent = [datafromservice requestdata:temparray fromurl:tabletype == 0?around_friend_info_url:around_fishing_store_and_area_info_url];      nsarray *responsearray = (nsarray *)[self checkrequestresponse:strcontent];     if (responsearray) {         nsmutablearray *temparray = [[nsmutablearray alloc]init];         switch (tabletype) {             case tabletype_frinedsaround:                 temparray = [[formatdata shareinstance] formatdicttofriendsaround:responsearray];                 break;             case tabletype_fishingstorearound:                 temparray = [[formatdata shareinstance] formatdicttofishingstorearound:responsearray];                 break;             case tabletype_fishingareaaround:                 temparray = [[formatdata shareinstance] formatdicttofishingareaaround:responsearray];                 break;             default:                 break;         }          if (self.delegate && [self.delegate respondstoselector:@selector(requestdatasuccess:responses:)]) {             [self.delegate requestdatasuccess:self responses:temparray];             return;         }     } }); } 

dispatch_get_current_queue() 

gets background queue, because using performselectorinbackground, gets called background queue.

dispatch_get_main_queue() 

dispatch_async returns immediately, don't need use performselectorinbackground:. can call dispatch_async directly:

dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_high, 0), ^{ ...     dispatch_async(dispatch_get_main_queue(), ^{     ...     }); ... }); 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -