ios - Update labels in UITableViewCell from multiple threads -


after getting data multiple device, reloading tableview tableview flashing labels. example, 2 rows in tableview contains 2 labels each. when call reload tableview, displaying data in first row , second row empty , when displaying second row, first row empty. flashing please me how can solve this

like reloading tableview

[devicestableview performselectoronmainthread:@selector(reloaddata)                                    withobject:nil                                 waituntildone:no]; 

this cellforatindexpath method:

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath{     static nsstring *simpletableidentifier = @"devicecustomtableviewcellidentifier";      devicescustomtableviewcell = (devicecustomtableviewcell *)[tableview dequeuereusablecellwithidentifier:simpletableidentifier];     if (devicescustomtableviewcell == nil)     {         nsarray *nib = [[nsbundle mainbundle] loadnibnamed:@"devicecustomtableviewcell" owner:self options:nil];         devicescustomtableviewcell = [nib objectatindex:0];     }      devicedetails *devicedetailsentity = [devicesarray objectatindex:indexpath.row];      devicescustomtableviewcell.devicename.text = devicedetailsentity.devicelocalname;      (int i=0; i<[dataarray count]; i++) {         deviceparticulars *deviceparticulars = [dataarray objectatindex:i];         if ([[[deviceparticulars.peripheral identifier] uuidstring] isequaltostring:devicedetailsentity.deviceaddress]) {              devicescustomtableviewcell.temperaturevaluelabel.text = deviceparticulars.tempreadoutstr;       } 

in this, devicedetails class core data class, in saving ble device name per requirement.

deviceparticulars class nsobject class saving data multiple ble devices getting temperature multiple devices. displaying temp values in tableview.

dataarray array contains deviceparticulars object.

reloading entire table every time peripheral value changes expensive and, seeing, has visual impacts.

you can change custom cell act delegate model object - deviceparticulars

in deviceparticulars.h file, register delegate property , protocol

@property (weak,nonatomic) id delegate;  @protocol deviceparticularsdelegate - (void)didupdatedevice:(deviceparticulars *)device; @end 

in deviceparticulars.m file, update readings, call

[self.delegate didupdatedevice:self]; 

then in devicecustomtableviewcell.h, add <deviceparticularsdelegate> class definition , add property store deviceparticulars

@property (strong,nonatomic) deviceparticulars *mydevice; 

in .m implement delegate method

-(void)didupdatedevice:(deviceparticulars *)device {    // update cell labels required } 

and implement prepareforreuse

- (void)prepareforreuse {     self.mydevice.delegate=nil;  // remove cell delegate existing device; } 

finally, set delegate in cellforrowatindexpath

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath{     static nsstring *simpletableidentifier = @"devicecustomtableviewcellidentifier";      devicescustomtableviewcell = (devicecustomtableviewcell *)[tableview dequeuereusablecellwithidentifier:simpletableidentifier];     if (devicescustomtableviewcell == nil)     {         nsarray *nib = [[nsbundle mainbundle] loadnibnamed:@"devicecustomtableviewcell" owner:self options:nil];         devicescustomtableviewcell = [nib objectatindex:0];     }      devicedetails *devicedetailsentity = [devicesarray objectatindex:indexpath.row];      devicescustomtableviewcell.devicename.text = devicedetailsentity.devicelocalname;      (int i=0; i<[dataarray count]; i++) {         deviceparticulars *deviceparticulars = [dataarray objectatindex:i];         if ([[[deviceparticulars.peripheral identifier] uuidstring] isequaltostring:devicedetailsentity.deviceaddress]) {              deviceparticulars.delegate=devicecustomtableviewcell;   //set delegate             devicescustomtableviewcell.mydevice=devicedetails;      //set device property              devicescustomtableviewcell.temperaturevaluelabel.text = deviceparticulars.tempreadoutstr;      } 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -