Obj-C,我如何可以附加一个NSMutableArray到另一个? [英] Obj-C, how can I append one NSMutableArray to another?

查看:97
本文介绍了Obj-C,我如何可以附加一个NSMutableArray到另一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将一个NSMutableArray附加到另一个,从我看到的,它听起来很直接。但是我得到了一些奇怪的结果,我认为我的临时数组中的项目的数量正在添加,但字典值正在丢失。

How can I append one NSMutableArray to another, from what I've seen, it sound be fairly straight forward. But I'm getting some weird results, I think the amount of items in my temp array are being added but the dictionary values are being lost.

这是我当前的代码,其中我只是覆盖我的self.transactionArray

This is my current code, where I just overwrite my self.transactionArray

h - file
NSMutableArray *transactionArray;
@property (nonatomic, retain) NSMutableArray *transactionArray;

m - file
NSMutableArray *arrayTmp= [[NSMutableArray alloc] init];

//start loop
[arrayTmp addObject:[NSDictionary dictionaryWithObjectsAndKeys:desc,@"desc",
         due,@"due",nil]];  
//release nsstring desc etc
//end loop

self.transactionArray = arrayTmp;

[arrayTmp release];

我的第二次尝试...

My second attempt...

NSMutableArray *array1 = [arrayTmp mutableCopy];
[self.transactionArray addObjectFromArray:array1];

这是我第一次尝试...

This was my first attempt...

[self.transactionArray addObjectFromArray:arrayTmp];

我做错了什么?

推荐答案

你可以这样做:

[self.transactionArray addObjectsFromArray:arrayTmp];

另一方面,请在发布问题之前阅读文档。此方法很容易在 NSMutableArray 文档。

And on a side note, please always read the documentation before posting a question. This method is easily found in the NSMutableArray documentation.

这篇关于Obj-C,我如何可以附加一个NSMutableArray到另一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆