nameLabel 不起作用。当我运行应用程序时,出现以下错误: UITableViewCell nameLabel]: unrecognized selector sent to instance 0x1fc4e090. 但是,如果我将 nameLabel 设置为 textLabel,它就可以工作。
下面是我的代码:
@interface ViewController ()
{
NSMutableArray *books;
}
@end
- (void)viewDidLoad
{
Book *book1 = [Book new];
book1.name = @"The adventures of tintin";
book1.imageFile = @"tintin.jpg";
Book *book2 = [Book new];
book2.name = @"Avatar";
book2.imageFile = @"avatar.jpg";
books = [NSMutableArray arrayWithObjects:book1, book2, nil];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{<br>
static NSString *simpleTableIdentifier = @"BookCell";
UITableViewCell *cell = [tableV dequeueReusableCellWithIdentifier:simpleTableIdentifier];
//MyBookCell *cell = [tableV dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
//if (cell == nil) {
cell = [[MyBookCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
Book *bk = [books objectAtIndex:indexPath.row];
cell.nameLabel.text = bk.name; (customised label)
return cell;
}
这是自定义表格单元格的头文件
@interface MyBookCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@end