簡體   English   中英

cell.detailTextLabel.text無法正常工作...為什么

[英]cell.detailTextLabel.text not working… why

使用以下代碼,我得到了text.label而不是detailTextLabel.text。 NSLog顯示正確。

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]];     

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

約翰

確保與此配合使用了合適的UITableViewCellStyle (因此,除了UITableViewCellStyleDefault任何東西都應該可以使用)。 初始化時指定單元格的樣式。

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

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

切記更改為UITableViewCellStyleSubtitle

如果選擇樣式UITableViewCellStyleSubtitle ,則detailTextLabel.text將顯示

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

UITableView源

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM