ios - 获取一个 NSArray

标签 ios arrays uitableview restkit

我想知道如何 结合两个 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/

相关文章:

ios - 在表格 View 中拉动刷新后滚动到屏幕顶部

iphone - 在运行时重新加载自定义 UITableViewCell 的 Nib

javascript - 无法在 for 循环中检索数组值

iphone - 移动容器 UIView 时 UITableView 调整大小

ios - 如何根据条件创建 UITableView 单元格?

ios - 获取图像后从其 imageView 刷新 UITableViewCell 布局

ios - 由于 NSObjectInaccessible 异常,无法更新 NSManagedObject

javascript - 第一次 TouchableOpacity 推送时从 FlatList 记录的数据为空

php - JavaScript 数组 id 循环

arrays - 通用异步数组的 enumerate() 方法