iOS 7 TableView 出队不起作用

标签 ios objective-c uitableview

我遇到了一个非常烦人的问题,我不确定为什么会这样。

我设置了表格 View ,我在单元格中有正确的标识符,但它仍然让我“无法使具有标识符单元格的单元格出列 - 必须为标识符注册一个 nib 或一个类或连接 Storyboard中的原型(prototype)单元格”当我运行它时。

代码看起来像这样

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    NSDictionary *event = [self.events objectAtIndex:indexPath.row];
    cell.textLabel.text = [event objectForKey:@"name"];

    return cell;
}

任何帮助都会很棒,因为我想撕掉我的头发。该表已连接到该类,然后 Cell 具有该 @"Cell"标识符

最佳答案

重新检查所有 4 个步骤

第一步:
你的 cellForRowAtIndexPath 应该是这样的

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier   forIndexPath:indexPath];

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

NSDictionary *event = [self.events objectAtIndex:indexPath.row];
cell.textLabel.text = [event objectForKey:@"name"];

return cell;
}

第 2 步:您的“ViewController.m”文件应如下所示
#import "ViewController.h"

@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>

@end

第三步:
请检查 - 单击 View Controller 移动到连接检查器 - 查看此检查器中是否存在任何其他不需要的连接。

Your Controller inspector should like this

第 4 步: Tableview 单元格属性检查器应该像这样]

Your Tableview cell attribute inspector should like this

关于iOS 7 TableView 出队不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21553352/

相关文章:

ios - 错误的多部分 - 在服务器上发布(json + 图像)

objective-c - 在 Cocoa 中创建 bundle

ios - 使用 Google API 在 Objective C 中查询共享的 Google 日历

iphone - 如何从 UITableView 中删除选定的行?

ios - 旋转后翻译 UIView

ios - 将所有图像放入 Assets 目录?

iphone - ffmpeg 不会在 iOS5.1 中进行 ./configure

android - 不使用应用程序 Radbeacon 检测信标?

ios - 通过 UICollectionView 的高度设置 UITableViewCell 的高度

ios - 在自定义 UITableViewCell 中包含的 UITableView 中显示相同的内容