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 the tableView up and down I get a crash one
this line where the message is EXC_BAD_ACCESS (code = 1, address
=0xsomething-something)
After the crash I tried printing
self.eventAssociation.associatedEvent.searchScheduleString on the debugger
console, I get the value of the string.
I bring the sequence again responsible for this crash. I thought probably
it is that because my model eventAssociation was assign and was getting
released but I was still referring to the old address of a deallocated
object, so made the model as retain property.but I am still getting this
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 is my cellForRowAtIndexPath method where I setTheEventAssociation
model and then call updateFromModel which then updates the labels with the
new model values.
this is the code for 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 where 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 is where I get the crash. What could be the reason ?
No comments:
Post a Comment