3

単一のデータソースから、さまざまなセクションで tableView にデータを一覧表示する方法を知りたかったのです。

私が見たすべての例には、配列の数 = セクションの数がありました。私が欲しいのは、3D nsmutableArray があると仮定することです。

If dArray.Id = 1 { //add to first section of UITableView }
else add to Section 2 of UITableView.

おそらく無理ですが、方向性が必要です。

4

1 に答える 1

4

はい、それは可能です。

コンテンツ全体を含む単一のNSMutableArray( ) を含めることができます。resultArray

次に、cellForRowAtIndexPathメソッドでこのようにすることができます

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

    if(indexPath.section == 0)
    {
        cell.text=[resultArray objectAtIndex:indexPath.row];
    }
    else if(indexPath.section == 1)
    {
        cell.text=[resultArray objectAtIndex:(indexPath.row+5)];
    }
    else if(indexPath.section == 2)
    {
         cell.text=[resultArray objectAtIndex:(indexPath.row+11)];
    }
}

そしてnumberOfRowsInSection

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

    NSInteger count;
    if(section == 0)
    {
        count=6;
    }
    else if(section == 1)
    {
        count=6;
    }
    else if(section == 2)
    {
        count=4;
    }
    return count;
}
于 2009-09-29T09:26:51.147 に答える