我想知道如何 结合两个 array
合二为一array
.
我想要合并的 tableView
显示最新的。
我会根据需要发布任何额外的代码或帮助,非常感谢!
最佳答案
在您的 UITableViewDataSource 方法中,组合两个数组并相应地使用一个或另一个:
- (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;
}
关于ios - 获取一个 NSArray,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23795573/