我遇到了一个非常烦人的问题,我不确定为什么会这样。
我设置了表格 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 移动到连接检查器 - 查看此检查器中是否存在任何其他不需要的连接。
第 4 步: Tableview 单元格属性检查器应该像这样]
关于iOS 7 TableView 出队不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21553352/