2014-02-10 21 views
1

我有一個UITableView,我正在加載數據。標題標題顯示正常,但cell.textlabel.text未顯示任何內容。 (注意顏色不是白色時,它也不顯示)但我可以在AlertView中獲取cell.textlabel.text的值。UITableViewCell textlabel內容不顯示任何東西

任何幫助?

代碼:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"cellT"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 
    cell.textLabel.text = [[theTArray objectAtIndex:indexPath.section]objectAtIndex:0]; 
    // Configure the cell... 
    cell.textLabel.textColor = [UIColor blackColor]; 
    return cell; 
} 
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 
{ 

    return [[theTArray objectAtIndex:section]objectAtIndex:1]; 
} 

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 

    NSString *message = [NSString stringWithFormat:@"%@", cell.textLabel.text]; 
    NSString *title = [[theTArray objectAtIndex:indexPath.section]objectAtIndex:1]; 

    UIAlertView *theAlert = [[UIAlertView alloc] initWithTitle:title message:message delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
    [tableView reloadData]; 


    [theAlert show]; 
} 

照片管理: http://imgur.com/a/lcwyf

回答

0

我在第一個字符數組中的每個文本中都有一個換行符。所以刪除它,現在一切正常。

0

確保您cell.textLabel具有高度和寬度。

嘗試在設置文本後調用 [cell.textLabel sizeToFit];

+0

試過了,沒有工作:( –

0
cell.textLabel.text = [[theTArray objectAtIndex:indexPath.section]objectAtIndex:0]; 

您的索引有問題。你的意思是indexPath.row而不是零索引? 在當前實現中,節中的所有單元格將具有相同的標題。

+0

不,我用一個多維數組 –

+0

好,分配給'cell.textLabel.text'之前登錄文本。你會得到什麼? – vokilam

+0

2014年2月10日19時37分28秒:816 RGZH [63632:1803] - [TermineViewController tableView:cellForRowAtIndexPath:] [Line 88] TEXT: Maturitätsarbeit,MeldungausstellungswürdigerMaturitätsarbeiten...(確切地應該是) –

0

確保您返回正確numberOfRowsInSection

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 

    return [self.theTArray count]; 
} 

cellForRowAtIndexPath

NSString *messageAtIndexPath = [[theTArray objectAtIndex:[indexPath row]]objectAtIndex:0]; 

確保您既代表和數據源都被設置。

+0

嘗試過兩種方法,也沒有任何效果注意:節標題顯示正常,所以數據源應該沒問題? –