Objective C - UITableViewCell在滚动时崩溃

时间:2010-11-12 18:57:08

标签: objective-c uitableview

我有一个带有这样的方法的UITableViewCell。

-(void) setupStore:(StoreModel *) store {
    self.title.text = store.title; // crash here when scrolling
}

因此,从包含UITableView的UIViewController类中调用该方法 像这样的东西

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ...
    [cell setupStore:[storesArray objectAtIndex:indexPath.row]];
    ...
}

当表首次加载时有效,但是当我滚动表时,它会因错误EXC_BAD_ACCESS而崩溃。

可能导致什么?

请开心。

谢谢,
三通

2 个答案:

答案 0 :(得分:1)

尝试使用NSZombieEnabled = YES构建代码,并在此处报告发生的情况。给我们完整的错误说明。

http://cocoa-nut.de/?p=16

答案 1 :(得分:0)

一般情况下,当我们尝试使用已发布的对象时,我们将获得EXC_BAD_ACCESS。

因此,您可以检查是否正在使用任何已发布的对象。

正如您所提到的那样storesArray = [[[storesLocation alloc] init]retain];,不需要保留该对象。尝试使用此行

storesArray = [[storesLocation alloc] init];.

还要通过在此方法中记录storemodel对象来确保它存在

-(void) setupStore:(StoreModel *) store
{
   NSLog(@"store model %@",store);
}
You can go through the link

https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmPractical.html