ios - 未为所有部分调用 cellForRowAtIndexPath

标签 ios uitableview

我有一个包含五个部分的 UITableView。正如标题所描述的那样,cellForRowAtIndexPath 仅在前四个中被调用。已建立有关数据源和委托(delegate)的所有连接。此外,我的 numberOfSectionsInTableView 清楚地返回 5。从 cellForRowAtIndexPath 中打印出部分的数量显示正确的数字,从而确认 cellForRowAtIndexPath 根本没有被所有部分调用。这到底是怎么回事?我很努力地寻找这个问题的答案,但找不到。如果已经回答了这个问题,请原谅我并指出正确的方向。

我的 cellForRowAtIndexPath:

- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [theTableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    switch (indexPath.section) {
        case 0:
            cell.textLabel.text = ticket.description;
            break;
        case 1:
            cell.textLabel.text = ticket.ticketStatus;
            break;
        case 2:
            cell.textLabel.text = ticket.priority;
            break;
        case 3:
            cell.textLabel.text = ticket.customerOfficePhone;
            break;
        case 4: {
            //This never ever gets executed
            Comment *comment = [ticket.comments objectAtIndex:indexPath.row];
            cell.textLabel.text = comment.commentContent;
            break;
        }
    }

    return cell;
}

我的 numberOfSectionsInTableView:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 5;
}

我的 numberOfRowsInSection:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSInteger numberOfRows;

    if (section == 4) {
        numberOfRows = [ticket.comments count];
    }
    else {
        numberOfRows = 1;
    }

    return numberOfRows;
}

如有任何建议,我们将不胜感激。提前致谢。

最佳答案

啊哈!我想到了。我忘记了我已经为我的表格 View 硬编码了框架并将其添加为 subview ,禁用滚动到 ScrollView 。不幸的是, ScrollView 和表格 View 的高度都太小,无法容纳第五部分,我想这是除了第五部分之外的所有部分都被调用 cellForRowAtIndexPath 的原因。将我的表格 View 和 ScrollView 的高度重新调整得更大一点已经解决了我的问题。

关于ios - 未为所有部分调用 cellForRowAtIndexPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9915401/

相关文章:

ios - stdargs [va_start()、va_arg() 等] 在 arm64 上损坏了吗?

objective-c - 从表格 View 中获取单元格标题

ios - UIImageView 在特定数量的循环迭代后停止显示图像

iOS 警报行为与相同的 APNS 消息不一致

ios - UIActivityIndi​​catorView 在 TableView 单元内

iphone - 如何dequeueReusableCellWithIdentifier : work?

ios - UITableViewCell - 如何隐藏删除tableview行的编辑模式

ios - 滚动完成时居中单元格 UITableView

c# - 依赖注入(inject)的 Xamarin iOS Controller 自定义继承问题

ios - UIViewController 的 prefersStatusBarHidden 不起作用