2014-12-06 45 views
0

我想在UITableViewCell上設置字幕標籤。我有一個包含標題和副標題對的字典,密鑰列表存儲在self.results中。但是,當我運行以下代碼:DetailTextLabel行爲奇怪

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Search Result Cell" forIndexPath:indexPath]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Search Result Cell"]; 
    } 
    cell.textLabel.text = [self.results objectAtIndex:indexPath.row]; 
    cell.detailTextLabel.text = self.resultPairs[[self.results objectAtIndex:indexPath.row]]; 
    NSLog(@"%@", self.resultPairs[cell.textLabel.text]); 

字幕保持空白,但NSLog打印正確的輸出。這裏發生了什麼?當我將detailTextLabel設置爲常量時,它工作正常。

+0

你是如何獲得'細胞'的? – FlyingPiMonster 2014-12-06 13:08:16

+0

我會編輯問題,但標題設置正確,所以我知道我有正確的單元格。 – stmfunk 2014-12-06 13:08:53

+0

確保self.resultPairs [[self.results objectAtIndex:indexPath.row]]不爲零。 – Mat 2014-12-06 13:15:12

回答

0

解決方案證明這些字符串包含了所有初始空格,導致它們被填充到視圖外。

0

問題是默認的單元格樣式不包含字幕。如果您正在使用故事板,則只需在Interface Builder中將樣式設置爲「字幕」即可。

+0

不,我將單元格類型從默認值更改爲副標題,原型單元格顯示其下方的標題和詳細信息。 – stmfunk 2014-12-06 13:24:15

+0

@stmfunk你想讓它看起來像什麼? – FlyingPiMonster 2014-12-06 13:40:19

+0

它應該是正確設置的標題和self.resultPairs [[self.results objectAtIndex:indexPath.row]];的內容。在它下面。如果我用字符串替換前面提到的代碼,我可以設置字幕 – stmfunk 2014-12-06 13:44:15