2013-08-17 43 views
0

我想做一個tableview單元格分成UICEVIEW分組的部分。我環顧四周,發現如何將它分成幾個部分,儘管我被困在讓他們出現在他們應該出現的組中,而不是三個組中的所有單元,這是我現在擁有的這個單元走到這一步,做了一些研究之後:如何分組UITableView單元格

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    UITableViewCell *cell = nil; 
    if ([indexPath section] == 0) { 
     if (indexPath.row == 0) { 
      cell = cell1; 
     } else if (indexPath.row == 1) { 
      cell = cell2; 
     } else if (indexPath.row == 2) { 
      cell = cell3; 
     } 
    } 
    if ([indexPath section] == 1) { 
     if (indexPath.row == 0) { 
      cell = cell4; 
     } else if (indexPath.row == 1) { 
      cell = cell5; 
     } else if (indexPath.row == 2) { 
      cell = cell6; 
     } 
    } 
    if ([indexPath section] == 2) { 
     if (indexPath.row == 0) { 
      cell = cell7; 
     } 
    } 
    return cell; 
} 

雖然當我運行,並轉到這一觀點的應用程序崩潰,並在NSLog的盒子也與此錯誤出現:

*** Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2380.17/UITableView.m:5471 

謝謝前進

+0

這看起來像一個完全錯誤的方法。什麼是cell1,cell2等?通過讓數據源數組成爲一個數組數組(通常)來獲得部分。在多個節中,您返回數組的數量,並在numberOfRows中返回每個內部數組的數量。 – rdelmar

+0

@rdelmar我正在使用xib上的uitableview單元格,並將它們拉入。這就是它們的樣子 – Hive7

+0

並且您是否有7種不同的單元格? – rdelmar

回答

1

行索引從零開始,用於eac h新的部分。

例如:

if ([indexPath section] == 2) { 
    if (indexPath.row == 3) { 

應該是:

if ([indexPath section] == 2) { 
    if (indexPath.row == 0) { 

此外,部分指標也從零開始,所以你可能要減小各指標在你的if語句。

+0

我試過,雖然似乎沒有工作會更新我現在擁有的問題 – Hive7

相關問題