我想在UITableViewController上實現自定義視圖單元格。自定義tableViewCell標籤不顯示
@interface PPCustomCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel *tableViewTitle;
@property (weak, nonatomic) IBOutlet UILabel *tableViewSubtitle;
@end
PPCustomCell *cell = (PPCustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell.accessoryView == nil) {
UIImage *buttonUpImage = [UIImage imageNamed:@"button4.png"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage:buttonUpImage
forState:UIControlStateNormal];
[button setTitle:@"Unpaid" forState:UIControlStateNormal];
[button sizeToFit];
[button addTarget:self
action:@selector(tappedButton:)
forControlEvents:UIControlEventTouchUpInside];
cell.accessoryView = button;
}
cell.accessoryView.tag = indexPath.row;
cell.tableViewTitle.text = [[remindersArray objectAtIndex:indexPath.row]reminderName];
cell.tableViewSubtitle.text =[[remindersArray objectAtIndex:indexPath.row]reminderDueDate];
,但得到這個錯誤 'NSInvalidArgumentException' 的,理由是:「 - [UITableViewCell的tableViewTitle]:無法識別的選擇發送到實例
請幫助。
更新 - 我正在使用它,刪除了它的工作線。 [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:CellIdentifier];
謝謝大家。
貴'PPCustomCell'類有一個屬性名爲'tableViewTitle'?錯誤說它沒有。 – rmaddy
您是否記得將單元格的類(在故事板或xib中)更改爲您的自定義類。錯誤消息是說你試圖訪問UITableViewCell上的一個屬性,而不是你的PPCustomCell。 – rdelmar
也許你忘了設置從視圖控制器切換到表視圖控制器的東西?你的應用顯然分配了UITableViewCell對象而不是PPCustomCell對象。 – johnyu