cellForRowAtIndexPath:返回nil

时间:2015-12-07 22:32:18

标签: ios objective-c uitableview

所以我有一个通用应用程序,如果tableView中的下一个单元格有错误状态,我正试图隐藏单元格的边框。我在tableView:cellForRowAtIndexPath:中使用此代码来确定单元格是否应该隐藏它的底部边框:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    DCSMCDynamicBaseCell * cell = [self.cellManager dynamicCellForComponent:[self componentForIndexPath:indexPath] atIndexPath:indexPath canShowErrors:self.shouldDisplayErrors];

    NSIndexPath *nextIndexPath = [self.tableView nextRowForIndexPath:indexPath];
    if (nextIndexPath) {
        DCSMCDynamicBaseCell *nextCell = [self.tableView cellForRowAtIndexPath:nextIndexPath];
        DCSMCDynamicBaseCell *currentCell = [self.tableView cellForRowAtIndexPath:indexPath];
        if (nextCell.invalidState) {
            cell.shouldHideBottomBorder = YES;
            NSLog(@"%@", currentCell);
        }
    }

    if ([cell isKindOfClass:[DCSMCDynamicCopyCell class]]) {
        [((DCSMCDynamicCopyCell *)cell).webView setNavigationController:self.navigationController];
    }
    [cell setDelegate:self];

    self.previousIndexPath = indexPath;
    return cell;
}

我的nextRowForIndexPath看起来像这样:

- (NSIndexPath *)nextRowForIndexPath:(NSIndexPath *)indexPath {
    NSInteger currentRow = indexPath.row;
    NSInteger currentSection = indexPath.section;
    NSInteger numberOfRows = [self numberOfRowsInSection:indexPath.section];
    NSInteger numberOfSections = [self numberOfSections];

    NSIndexPath *newIndexPath;
    if (currentRow + 1 < numberOfRows) {
        newIndexPath = [NSIndexPath indexPathForRow:currentRow + 1 inSection:currentSection];
    } else if (currentSection + 1 > numberOfSections) {
        newIndexPath = [NSIndexPath indexPathForRow:0 inSection:currentSection + 1];
    } else {
        newIndexPath = nil;
    }

    return newIndexPath;
}

在我的iPhone 6模拟器上,一切正常。它获取单元格并隐藏它的底部边界。我可以稍微重构一下,以确保它适用于所有场景,但是在测试之前的第一遍,它可以很好地工作。

问题出在iPad上,使用cellForRowAtIndexPath:方法时,每个单元格返回nil。甚至更奇怪,在iPad上,屏幕足够大,以便所有单元格始终可见,因此当我调用重载数据时,单元格已经可见,应该通过此方法返回。

有谁知道为什么iPad上的cellForRowAtIndexPath:不会返回一个单元格,而是会在iPhone上退回?

0 个答案:

没有答案