Iphone 从单个nsmutablearray向UITableView的2个部分添加数据

Iphone 从单个nsmutablearray向UITableView的2个部分添加数据,iphone,xcode,uitableview,nsmutablearray,Iphone,Xcode,Uitableview,Nsmutablearray,我想知道如何在tableView中列出来自单个数据源的不同部分的数据 我看到的所有示例都有数组数=节数。我想要的是假设我有一个3d nsmutableArray If dArray.Id = 1 { //add to first section of UITableView } else add to Section 2 of UITableView. 这很可能是可行的,但我需要一个方向。是的,这是可能的 您可以拥有一个包含全部内容的NSMutableArray(resultArray) 然后

我想知道如何在tableView中列出来自单个数据源的不同部分的数据

我看到的所有示例都有数组数=节数。我想要的是假设我有一个3d nsmutableArray

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

这很可能是可行的,但我需要一个方向。

是的,这是可能的

您可以拥有一个包含全部内容的
NSMutableArray
resultArray

然后在
cellforrowatinexpath
方法中,您可以这样做

- (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)];
    }
}
numberofrowsin部分

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