0

我正在使用下面的代码并获取(使用未声明的标识符“TableCell”)
在属性属性检查器中 TableCell 已经在自定义下定义

任何想法?

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

    // Configure the cell...

    int row = [indexPath row];
    cell.TitleLabel.text = _Title[row];
    cell.Desctiptionlabel.text = _Description[row];
    cell.ThumbImage.image = [UIImage imageNamed:_Images[row]];

    return cell;
}
4

1 回答 1

2

如果你使用 dequeueReusableCellWithIdentifier:forIndexPath: 方法,你必须记得先用类或 NIB 注册标识符。

你的类的代码在 viewDidLoad 中可能看起来像下面这样。

[self.tableView registerNib:[UINib nibWithNibName:"TableCell" bundle:nil] forCellReuseIdentifier:CellIdentifier];

或者,您可以使用较旧的 dequeueReusableCellWithIdentifier: 方法,但您必须处理出队后单元格为 nil 的情况,您需要从 nib 加载单元格或手动实例化新对象。

顺便说一句,Objective-C 开发中的约定是使用小写驼峰式类成员名称和局部变量。

于 2014-08-10T06:00:50.407 回答