ios - 具有自己的 Nib 和 UITableViewCell 子类的 TableViewCell 设计

标签 ios uitableview

我已将 UITableViewCell 子类化为 MyCell 并尝试显示表格。我总是收到消息:

异常“NSInternalInconsistencyException”,原因:“UITableView dataSource 必须从 tableView:cellForRowAtIndexPath 返回一个单元格:

tableView:cellForRowAtIndexPath的代码如下:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
MyCell* cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
MyCell* theCell = (MyCell *)cell;
UILabel* lab = theCell.theLabel;
lab.text = @"This is the label text";
return cell;
}

我已将 Nib 中的 CellIdentifier 设置为“Cell”。我以为我正在返回带有最后一行的单元格? 我哪里错了?

最佳答案

您的单元格必须为零。你应该将类似的白色设置为:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    MyCell* cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (!cell) {
        cell = [[NSBundle mainBundle] loadNibNamed:@"MyCell"].lastObject;
    }
    // Configure the cell...
    UILabel* lab = cell.theLabel;
    lab.text = @"This is the label text";
    return cell;
}

关于ios - 具有自己的 Nib 和 UITableViewCell 子类的 TableViewCell 设计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13941167/

相关文章:

ios - 谷歌地图 SDK 版本 1.5 与 iOS 7 应用程序集成

ios - RxSwift 重新加载表格 View

ios - 具有 RGB 的 UIColors 在屏幕上显示为基本颜色

ios - facebook SDK react native : no framework search path

ios - 如何在 webpack/babel 构建中使用 CustomElement v1 polyfill?

iOS 静态库 Xcode(链接错误)

ios - 如何将 UIButton 左对齐,UILabel 右对齐。喜欢 instagram 的评论

ios 6 UITableViewCell 删除按钮有背景色

ios - 在页 footer 分创建按钮并检测正确的点击

ios - swift : how to blurry a cell on tap in tableView