UITableView滚动崩溃应用程序

时间:2011-08-30 12:26:50

标签: iphone ios uitableview

当我滚动UITableView时,它会崩溃应用程序。这是代码。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary *tempDict = [albums objectAtIndex:indexPath.row];

static NSString *CellIdentifier = @"ImageCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
   cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
} else {
    AsyncImageView *oldImage = (AsyncImageView *)[cell.contentView viewWithTag:999];
    [oldImage removeFromSuperview];
}

我设置断点并在行

处停止
NSDictionary *tempDict = [albums objectAtIndex:indexPath.row];

我做错了什么? 提前谢谢。

5 个答案:

答案 0 :(得分:1)

我不确定,首先请检查总行数和数组计数。它们必须相同。如果它仍然崩溃然后把这条线

NSDictionary *tempDict = [[albums objectAtIndex:indexPath.row] copy];

答案 1 :(得分:0)

检查相册数组的大小。可能它比indexPath.row小,或者它在某个地方发布。

答案 2 :(得分:0)

确保您没有读出您的NSdictionary范围。

检查tableView:numberOfRowsInSection: dataSource方法中的返回值。

答案 3 :(得分:0)

该行崩溃的最可能原因是您的表格视图的行数多于相册数组中的项目数量。通常,在这样的设置中,表中的行数完全相同,并且-tableView:numberOfRowsInSection:的实现看起来像这样

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // assuming that there is only one section
    return [albums count];
}

答案 4 :(得分:0)

我解决了这个问题。实际上在$ c​​ellForRow中,我试图从服务器获取信息,我没有在那里应用延迟加载。因此,在滚动tableView时,应用程序崩溃了。

感谢大家的帮助。

相关问题