谁来设置 UIViewController 中的 tableView 单元格标识符?
使用 UITableViewController
我总是通过界面来完成(见下面的截图)
现在,如果我使用 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)单元格来弄乱我的界面。
最佳答案
这里有几件事:
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/