我想要得到一個表來顯示名稱和排名列表。在每個單元格中,我想要有2個UILabel作爲子視圖 - 一個UILabel顯示排名,一個UILabel顯示名稱。Setter方法不工作的一個UITableViewCell子類的屬性
@interface MyTableViewCell : UITableViewCell
@property UILabel* rankLabel;
@property UILabel* nameLabel;
我還沒有添加任何東西比MyTableView @synthesize各性能的其他的.M實現文件:
我如下創建一個UITableViewCell子類具有兩個屬性。實現文件的其餘部分正是xCode在創建UITableViewCell子類時爲您提供的內容。
然後,在包含該表的masterViewController,我有以下幾點:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
Person *object = _objects[indexPath.row];
if (cell == nil) {
cell = [[MyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
cell.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(cell.frame.size.height, 0, cell.frame.size.width - cell.frame.size.height, cell.frame.size.height)];
cell.nameLabel.text = object.name;
[cell addSubview:cell.nameLabel];
NSString* rankString = [object.rank stringValue];
cell.rankLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, cell.frame.size.height, cell.frame.size.height)];
cell.rankLabel.text = rankString;
[cell addSubview:cell.rankLabel];
}
當我在調試運行它,它會在那裏我設置cell.nameLabel或Alloc它的第一線,和拋出以下錯誤:
[UITableViewCell setNameLabel:]: unrecognized selector sent to instance 0x108fa64c0
真的不明白爲什麼setNameLabel方法應該有問題在這裏。有任何想法嗎?提前致謝。
你是不是在使用故事板?或者只是不爲這個特定的細胞? –