iphone - 如何组合两个可变数组?

标签 iphone ios ipad

我有一个 iPhone 应用程序,我试图在其中添加两个可变数组。

NSMutableArray *dataArray = [[NSMutableArray alloc] init];
NSMutableArray *dataArray1 = [[NSMutableArray alloc] init];
NSDictionary *news = [dict objectForKey:@"news"];
NSDictionary *deals = [dict objectForKey:@"deals"];
NSLog(@"%@", [news classForCoder]);
NSLog(@"%@", news);

for (NSDictionary *key in news)
{ 
    if ([key isKindOfClass:[NSDictionary class]])
    {
        [dataArray addObject:key];      
    }
}

for (NSDictionary *key in deals)
{
    if ([key isKindOfClass:[NSDictionary class]])
    {
        [dataArray1 addObject:key];        
    }
}

self.newssarray = dataArray;
[self.mTableView reloadData];

这里我想添加两个数组 'dataArray' 和 'dataArray2' 以组合成一个数组 (self.newsarray)。谁能帮我实现这个目标?

最佳答案

NSMutable 数组具有 NSArray 的所有方法,包括通过向自身添加另一个数组来创建新数组的方法:

self.newsarray = [[dataArray arrayByAddingObjectsFromArray:dataArray1] mutableCopy];

关于iphone - 如何组合两个可变数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11397514/

相关文章:

iphone - NSString 的问题

c# - Xamarin : UISearchController is not becoming first responder and editing is not getting started while adding it to Navigation Bar

iphone - CATransaction 未观察到 CALayer 子类上的属性

ios - 如何降低网速

iphone - 使用带有 HTTP Live Streaming 的 AV 播放器时预缓冲多少视频内容以及该值是否可以更改

iphone - 连接到 "E"时发生奇怪的崩溃

iOS 取消模态呈现的导航 Controller

iOS Guided Access 模式破坏了 HTML <select>

ios - 如果我没有使用 Xcode 启动它,我可以显示应用程序中发生的错误吗?

iphone - 如何在 subview 中添加 AVQueuePlayer 以显示 View