ios - 如何在 UIViewController 中设置 tableView 单元格标识符?

标签 ios objective-c uitableview

谁来设置 UIViewController 中的 tableView 单元格标识符?

使用 UITableViewController 我总是通过界面来完成(见下面的截图)

enter image description here

现在,如果我使用 UIViewController,我看不到该选项

这是我的代码

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    NSString *messageAtIndexPath = [messageArray objectAtIndex :[indexPath row]];
    [[cell textLabel] setText:messageAtIndexPath];

    return cell;
}

请多多指教

除非我添加一个原型(prototype)单元格来弄乱我的界面。

enter image description here

最佳答案

这里有几件事:

1) 一个 UITableViewController inherits 来自 UIViewController(我认为这是您实际谈论的内容,而不是“UIControllerView”)。 UITableViewControllers 有能力做原型(prototype)单元格并设置这些标识符...

2) ...区分大小写。在您的屏幕截图中,您将其称为“cell”,而在您的代码中,您将其称为“Cell”。

它们的拼写必须完全相同且大小写相同。

您在这里尝试做什么不是很清楚,但我感觉到您想在 XIB 或 Storyboard 中创建一个自定义单元格,然后在您的“cellForRowAtIndexPath:”方法中引用它。 Here is a tutorial that talks about prototype cells and identifiers and using them in storyboards ,希望这对您有所帮助。

关于ios - 如何在 UIViewController 中设置 tableView 单元格标识符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21688059/

相关文章:

objective-c - 指定初始化器应该只调用 'super' 上的指定初始化器

ios - 在单个按钮单击中隐藏多个 UIButton

ios - 将 JSON 解析为 tableview

javascript - 如何防止移动端Chrome的下拉刷新

ios - 区域设置 - 确定数字是否采用小数格式

ios - 在 XCode 7 中导入带有类别扩展的接口(interface)时编译和运行时失败

ios - UITableView 滚动后行颜色变化

iphone - 用于我的 iPhone 应用程序的 Google Places API

ios - 具有输入格式的 UItextfield

ios - [self addSubview] 和 [self.contentview addSubView] 中的服装 UITableViewCell 有什么区别?