2017-07-17 43 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

謝謝我發現了這個問題:一個視圖被設置爲「隱藏」,我不知道如何! (我知道這是一個愚蠢的錯誤)。再次感謝你! –

相關問題