2014-01-20 37 views
1

我有一个单元格的表格,其中字幕只出现在搜索到的东西后面。这是cellForRowAtIndexPath代码:UITableViewCell字幕没有出现在加载

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if(!cell) 
    { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    } 

    if(tableView == self.tableView) 
    { 

     // Configure the cell... 
     cell.textLabel.text = self.objects[indexPath.row]; 
     cell.detailTextLabel.text = @"test2"; 
    } 
    else{ 
     // Configure the cell... 
     cell.textLabel.text = self.results[indexPath.row]; 
     cell.detailTextLabel.text = @"test1"; 

    } 

    return cell; 
} 

编辑:ArtOfWarfare的答案是正确的。这是故事板中的问题。见下图:

enter image description here

+0

so ...''detailTextLabel.text'不显示任何东西,直到你搜索something.hm ...在搜索前怎么样'textLabel.text'? – staticVoidMan

+0

它在那里,它看起来就像当我使用'UITableViewCellStyleDefault' –

+1

也许这... http://stackoverflow.com/a/10500210/2857130 – staticVoidMan

回答

1

您的代码表明,你有两个独立的表......我建议,你的问题在于差异中如何表已经配置,可能在你的故事板。

你是否有其中一个设置了一个标识符为“Cell”但不是UITableViewCellStyleSubtitle的样式的原型?这将使得你的单元格创建方法不是在一个中调用,而是在另一个中调用。

相关问题