【问题标题】:Can't load a custom UITableViewCell inside a UITableViewController无法在 UITableViewController 中加载自定义 UITableViewCell
【发布时间】:2015-10-02 15:31:52
【问题描述】:

我需要有关在 UITableViewController 中加载自定义 UITableViewCell 的帮助。预期的结果是有一个 UITableViewController,其中包含 3 个 UITableViewCell:3 个中有 2 个是常规 UITableViewCell,一个是自定义 UITableView 子类,名为 SubscriptionContentCell。根据内容存在、不存在或仍在从服务器加载的条件显示 3 个单元格。我对条件没有问题,但对库存有问题

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

我在其中放置代码以选择适当的 UITableViewCell 的方法。这是代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *cellIdentifier;
    id cell;

    if ([deactivableOrNotContents count] > 0) {
        cellIdentifier = @"subscriptionCell";
    } else {
        if (getPurchasedHasFired == true) {
            cellIdentifier = @"noContentsAvailable";
        } else {
            cellIdentifier = @"loadingCell";
        }
    }

    if ([deactivableOrNotContents count] > 0) {
        SubscriptionContentCell *contentCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        cell = contentCell;
    } else {
        UITableViewCell *standardCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        cell = standardCell;
    }

    // Configure the cell...
    if (cell == nil) {
        if ([deactivableOrNotContents count] > 0) {
            cell = [[SubscriptionContentCell alloc] initWithStyle:UITableViewCellStyleDefault
                                          reuseIdentifier:cellIdentifier];
        } else {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                          reuseIdentifier:cellIdentifier];
        }
    }

    return cell;
}

我遇到的问题是SIGABRT在线:

SubscriptionContentCell *contentCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

即使我导入了课程。

这是我的故事板文件中 UITableViewController 内的 UITableView 单元格:

我的代码有什么问题?

【问题讨论】:

  • 为什么要进行两次 if 检查?你可以一次性完成它们
  • 可能单元格标识符变为零,因为您将它们分配在不同的位置
  • 检查 XIB 看看是否有任何 IBOutlets 集不再存在于您的代码中。
  • 您是否在情节提要上设置单元格标识符?
  • @Aluminum 太好了——当然,我刚刚发布了一个更详细的答案。

标签: ios objective-c uitableview


【解决方案1】:

SIGABRT 消息可能由多种原因引起。最常见的可能是IBOutlet 仍链接在接口文件中,但已在您的代码删除

由于您是从 XIB 文件加载您的 UITableViewCell 对象,这很可能是您的问题的原因。检查您的SubscriptionContentCell 接口文件,看看是否有任何IBOutlets 链接到已从您的类代码中删除的子视图。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多