自定义单元格的“没有重复使用表格单元格的索引路径”问题

问题描述 投票:1回答:3

我有一个Tableview,我有一个自定义单元格,并在其中我有另一个tableview。在这个cellForRowAtIndexPath方法我得到这个错误no index path for table cell being reusedcell gets disappeared after scroll。这是indexpath问题还是cellidentifier问题?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CustomCell";
CustomCell *customCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];     
//    __block CustomCell *customCell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//    if (customCell == nil)
//    {
//        customCell = [[[CustomCell alloc] initWithFrame:CGRectMake(0, 0, 320, 416)] autorelease];
//   
// }
[customCell prepareCell:arrCategory];
return customCell;
}
-(void)prepareCell:(NSArray *)arrCategory
{
      if(mutArr != nil) {
        [mutArr removeAllObjects];
        mutArr = nil;
        [mutArr release];
 }
 mutArr = [[NSMutableArray alloc] arrCategory];
 [tblCusom reloadData];
}

我通过this SO ques,但我没有使用这个问题中使用的方法。那么可能是我无法追踪的问题。谷歌搜索后也没有找到相同的问题

objective-c ios6 uitableview custom-cell
3个回答
0
投票

如果我理解正确,你需要检查tableView(mainTableView或tblCustom)为其委托的调用方法。像这样的东西:

   - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        if (tableView == tblCusom)
        {
           __block CustomCell *categoryCell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
            if (customCell == nil)
            {
                customCell = [[[CustomCell alloc] initWithFrame:CGRectMake(0, 0, 320, 416)] autorelease];

            }

            [customCell prepareCell:arrCategory];
        }
        else if (tableView == self.myMainTableView)
        {
            static NSString *CellIdentifier = @"CustomCell";
            CustomCell *categoryCell = [tableView   dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
            return categoryCell;
        }

    return customCell;
}

希望它能帮到你。


0
投票

很长一段时间我也面临着这个错误并找到了解决方案: -

[tblCusom reloadData];

替换为

[self performSelector:@selector(tableReloadMethod) withObject:nil afterDelay:0.5];

添加此方法: -

-(void)tableReloadMethod
{
    [tblCusom reloadData];

}

希望它能帮到你。


0
投票
    CustomCell *categoryCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

您正在创建一个单元实例但不在任何地方使用它,并且该单元格正在从reuseIdentifier方法返回。所以实际上在您的代码中没有使用此行

© www.soinside.com 2019 - 2024. All rights reserved.