I was wondering how to combine two array
\'s into one array
.
I want the combined tableView
to show the most recent
In your UITableViewDataSource methods, combine both arrays and use one or another accordingly:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// API1 + API2
return hArray.count + iArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;
if(indexPath.row < hArray.count) {
// API 1
YourAPI1Cell *api1Cell = [tableView dequeueReusableCellWithIdentifier:@"YourAPI1Cell"];
// Do everything you need to do with the api1Cell
// Use the index in 'indexPath.row' to get the object from you array
cell = api1Cell;
} else {
// API 2
YourAPI2Cell *api2Cell = [tableView dequeueReusableCellWithIdentifier:@"YourAPI2Cell"];
// Do everything you need to do with the api2Cell
// Remember to use 'indexPath.row - hArray.count' as the index for getting an object for your second array
cell = api2Cell;
}
return cell;
}