Get one NSArray

后端 未结 4 1307
夕颜
夕颜 2021-01-24 00:48

I was wondering how to combine two array\'s into one array.

I want the combined tableView to show the most recent

4条回答
  •  失恋的感觉
    2021-01-24 01:19

    I would keep a single property for the table data:

    @property (strong, nonatomic) NSMutableArray *tableDataList;
    

    and have a method that is called in each success block:

    - (void)addTableData:(NSArray *)items
    {
        [self.tableDataList addObjectsFromArray:items];
        [self.tableDataList sortUsingDescriptors:...];
    
        [self.tableView reloadData];
    }
    

    to which you pass mappingResult.array and you fill in the sort descriptor information to get your timeline ordering.

    Then your table view delegate / data source methods are really simple and just refer to self.tableDataList.

    This is relatively similar to the answer from @Larme. From here I would get the item and check the class to decide how to configure the cell:

    id item = [self.tableDataList objectAtIndex:indexPath.row];
    
    if ([item isKindOfClass:[Feed class]]) {
        Feed *feed = (Feed *)item;
        ... // configure the feed cell
    } else {
        Data *data = (Data *)item;
        ... // configure the data cell
    }
    

提交回复
热议问题