self.detailTextLabel.text = self.eventAssociation.associatedEvent.searchScheduleString;
偶尔在上下滚动 tableView 时,我会在消息所在的这一行出现崩溃EXC_BAD_ACCESS (code = 1, address =0xsomething-something)
崩溃后我尝试self.eventAssociation.associatedEvent.searchScheduleString
在调试器控制台上打印,我得到了字符串的值。
我再次带来了对这次崩溃负责的序列。我想可能是因为我的模型 eventAssociation 已分配并被释放,但我仍然指的是已释放对象的旧地址,所以将模型设为保留属性。但有时我仍然会遇到这种崩溃。
- (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;
}
这是我的 cellForRowAtIndexPath 方法,我在其中设置了事件关联模型,然后调用 updateFromModel,然后使用新模型值更新标签。
这是 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];
}
第一行是我遇到崩溃的地方。可能是什么原因 ?