簡體   English   中英

如何對UITableView單元格進行分組

[英]How to Group UITableView cells

我正在嘗試將單元格分為uitableview的單元格制作一個tableview。 我四處張望,發現了如何將其分成幾部分,盡管我堅持讓它們像應該以組的形式出現一樣,而不是三組,每組中都有所有單元格,這就是我現在所擁有的經過一些研究后,到目前為止:

-(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

提前致謝

每個新部分的行索引都從零開始。

例如:

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

應該:

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

此外,段索引也從零開始,因此您可能希望減少if語句中的每個索引。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM