2017-07-17 49 views
0

我在我的UIViewController中有一个UITableView。第一个单元格有type1,其他单元格有type2。我的问题是,我的第一个单元格的内容从不显示。 这是我的代码:iOS:不显示不同类型的UITableView第一个单元格内容

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
     if(indexPath.row == 0) { 
      return 240; 
     } 
     return 90; 
    } 


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

    if(indexPath.row == 0) { 
     Type1Cell * tmpCell1 = [tableView dequeueReusableCellWithIdentifier:@"type1Cell"]; 

     if (tmpCell1 == nil) { 
      tmpCell1 = [[Type1Cell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"type1Cell"]; 
     } 

     //set data 
     return tmpCell1; 

    } else { 


    Type2Cell * tmpCell = [tableView dequeueReusableCellWithIdentifier:@"type2Cell"]; 

    if (tmpCell == nil) { 
     tmpCell = [[Type2Cell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"type2Cell"]; 
    } 
    //set data 

    return tmpCell; 
    } 


} 

第一个单元格具有相同的指定高度,但它总是空白。我没有与其他单元格的这个问题。

+0

检查xib或原型单元格中第一个单元的标识符 – KKRocks

+0

@KKRocks它与我在代码 –

+0

中所做的相同,请检查您是否对contentView或其他任何错误设置了隐藏。 –

回答

0

确保单元格内容视图或任何其他错误检查Hidden属性为TRUE。

-1

您还需要注册您的手机。

UINib *cellNib = [UINib nibWithNibName:@"Type1Cell" bundle:nil]; 
[self.tableView registerNib:cellNib forCellReuseIdentifier:@"type1Cell"]; 
+0

我不使用'Xib',我使用故事板 –

+0

你可以发布整个班级代码吗? – ppinho

+0

谢谢我发现了这个问题:一个视图被设置为“隐藏”,我不知道如何! (我知道这是一个愚蠢的错误)。再次感谢你! –

相关问题