0

UITableView に少し問題があります。サーバーから返された JSON を使用して tableView をロードしています。

Pastebin へのJSONリンク >

(何百もの項目が含まれていたため、読みやすくするためにいくつかの項目を削除しました) これは、PHP からの print_r() 出力です。

ご覧のとおり、サブ配列を使用しています。numberOfRowsInSection からセクションとカウントをログに記録すると、これは正しいです。

例えば、

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    if([tableView isEqual: self.timetableTableView]){

        NSDictionary *sectionContents = [_timetableDataArray objectAtIndex: section];
        NSLog(@"Section: %d, count: %d", section, [sectionContents count]);

        return [sectionContents count];
    }
    return 0;
}

戻り値、

Section: 6, count: 12
Section: 0, count: 35
Section: 1, count: 35
Section: 2, count: 38
Section: 3, count: 33
Section: 4, count: 19
Section: 5, count: 15

ここまでは順調ですね。テーブル ビューでは、セクションごとに正しい量のセクションとセルも描画されます。

今、私の問題は cellForRowAtIndexPath にあります。私が期待する回数は呼び出されていません。何が間違っているのかわかりません。

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

    if([tableView isEqual: self.timetableTableView]){

        static NSString *TimetableCellIdentifier = @"TimetableTableCell";
        TimetableTableCell *cell = (TimetableTableCell *)[tableView dequeueReusableCellWithIdentifier:TimetableCellIdentifier];

        if(cell == nil){

            NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"TimetableTableCell" owner:self options:nil];
            cell = [nib objectAtIndex:0];
        }


        // Get the day array out of my JSON.
        NSDictionary *dayContents = [_timetableDataArray objectAtIndex:indexPath.section];
        NSLog(@"Row: %d, Path: %d", indexPath.row, indexPath.section);

        return cell;
    }
}

これはログに記録し、

Row: 0, Path: 0
Row: 1, Path: 0
Row: 2, Path: 0
Row: 3, Path: 0
Row: 4, Path: 0
Row: 5, Path: 0


numberOfSectionsInTableView returns the correct amount of sections.
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {

        if([tableView isEqual: self.timetableTableView]){
            NSLog(@"sections: %d", [_timetableDataArray count]);
            return [_timetableDataArray count];
        }
        return 0;
    }

sections: 7

私が知る限り、cellForRowAtIndexPath は、JSON のみで days 配列を反復処理しています。numberOfRowsInSection には正しい量のセクション/セルがありますが。

日配列 (セクション) の内容を反復するように cellForRowAtIndexPath に指示するにはどうすればよいですか?

UITableViews でサブ配列をループすることは可能ですか?

どんな助けでも大歓迎です!ありがとう、エイドリアン

4

1 に答える 1