2010-02-27 95 views
32

使用下面的代碼我得到text.label而不是detailTextLabel.text。 NSLog顯示正確。cell.detailTextLabel.text not working ... why

cell.textLabel.text = [eventLabels objectAtIndex:indexPath.row]; 
cell.detailTextLabel.text = [eventFields objectAtIndex:indexPath.row]]; 

NSLog(@"%@", [eventFields objectAtIndex:indexPath.row]); 

我也試過......

cell.detailTextLabel.text = [NSString stringWithFormat:@"%@", [eventFields objectAtIndex:indexPath.row]];  

我以前沒有這個問題。有什麼建議麼?

約翰

回答

83

確保您使用適當的UITableViewCellStyle本(除了UITableViewCellStyleDefault應該這樣工作)。單元格的樣式在初始化時指定。

+0

這是它!!!!我正在使用,但UITableViewCellStyleDefault。我想我使用了當我創建課程時沒有考慮到的內容。非常感謝。 約翰 – user278859 2010-02-27 23:18:25

+10

user278859:如果John已經回答了你的問題,那麼請接受他的回答。如果你不接受正確的答案,有什麼用? – 2010-11-11 08:26:20

+0

像魔術一樣工作 – 2011-04-03 11:28:10

24
- (UITableViewCell *)tableView:(UITableView *)tableView 
     cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
            reuseIdentifier:CellIdentifier] autorelease]; 
} 

請記住改爲UITableViewCellStyleSubtitle

2

如果你選擇的風格UITableViewCellStyleSubtitle,你detailTextLabel.text將顯示

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
           reuseIdentifier:CellIdentifier] ; 

UITableView Source