2013-11-25 79 views
0

我想在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];

謝謝大家。

+2

貴'PPCustomCell'類有一個屬性名爲'tableViewTitle'?錯誤說它沒有。 – rmaddy

+1

您是否記得將單元格的類(在故事板或xib中)更改爲您的自定義類。錯誤消息是說你試圖訪問UITableViewCell上的一個屬性,而不是你的PPCustomCell。 – rdelmar

+0

也許你忘了設置從視圖控制器切換到表視圖控制器的東西?你的應用顯然分配了UITableViewCell對象而不是PPCustomCell對象。 – johnyu

回答

1

你沒有分配任何單元!

您的通話if (cell.accessoryView == nil)之前,您應該包括以下內容:

if (cell == nil) { 
    cell = [[PPCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:etc...]; 
} 
+0

但單元格不爲零 – user2769614

+1

如果單元格是在故事板中製作的,它不會是零,所以不需要這個檢查。 – rdelmar

相關問題