0

セルがセクションに分割され、uitableview がグループ化されたテーブルビューを作成しようとしています。私は周りを見回して、それをセクションに分割する方法を見つけましたが、現時点で私が持っているものである、それぞれにすべてのセルを含む3つのグループではなく、本来のようにグループに表示することに固執しています少し調査を行った後、これまでに得ました:

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

前もって感謝します

4

1 に答える 1

1

行インデックスは、新しいセクションごとにゼロから始まります。

例えば:

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

次のようにする必要があります。

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

さらに、セクション インデックスもゼロから始まるため、おそらく if ステートメントで各インデックスをデクリメントする必要があります。

于 2013-08-17T12:33:40.050 に答える