ios - EXC_BAD_ACCESS crash while assigning a string to the text of a cell's label -
self.detailtextlabel.text = self.eventassociation.associatedevent.searchschedulestring;
occassionally while scrolling tableview , down crash 1 line message exc_bad_access (code = 1, address =0xsomething-something)
after crash tried printing self.eventassociation.associatedevent.searchschedulestring
on debugger console, value of string.
i bring sequence again responsible crash. thought because model eventassociation assign , getting released still referring old address of deallocated object, made model retain property.but still getting crash sometimes.
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"cell"; boaeventlistcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; if(nil == cell ) { cell = [[[boaeventlistcell alloc] initwithstyle:uitableviewcellstylevalue1 reuseidentifier:cellidentifier] autorelease]; } if(nil != self.customtabledatasource) { if(indexpath.section < self.customtabledatasource.count) { nsarray *eventarray = [self.customtabledatasource objectforkey:[[self.customtabledatasource allkeys] objectatindex:indexpath.section]]; [cell seteventassociation:[eventarray objectatindex:indexpath.row]]; [cell updatefrommodel]; } } return cell; }
this cellforrowatindexpath method settheeventassociation model , call updatefrommodel updates labels new model values.
this code updatefrommodel,
-(void)updatefrommodel { self.detailtextlabel.text = self.eventassociation.associatedevent.searchschedulestring; cgsize sizeforschedule = [self.eventassociation.associatedevent.searchschedulestring sizewithfont: self.detailtextlabel.font]; cgrect frame = self.detailtextlabel.frame; frame.size = sizeforschedule; frame.origin.x = self.frame.size.width - (sizeforschedule.width + 20) ; self.detailtextlabel.frame = frame; // find out title should end cgfloat titleendx = self.detailtextlabel.frame.origin.x - 20; frame = self.eventtitle.frame; frame.size.width = titleendx - frame.origin.x; self.eventtitle.frame = frame; self.eventtitle.text= self.eventassociation.associatedevent.eventname; // adjusting size of cell based on text [self setneedslayout]; }
this first line crash. reason ?
as know exc_bad_access
means trying use released object . try retain object @ getting crash issue .
Comments
Post a Comment