简体   繁体   English

从iPhone中的多个数组添加数组中的对象

[英]add objects in array from multiple array in iphone

I have 2 array like as follow: 我有2个数组,如下所示:

Array A  ( 

{ title="A",id=1 }, {title="B",id=2},{title="c",id=3}

)

Array B  ( 

{ title="A",id=1 }, {title="B",id=2},{title="c",id=3}

)

Now, I want to combine this arrays & when I try to get the values from combined array, I want know that it is from Array A or Array B. 现在,我想combine this arrays ,当我尝试从组合数组中获取值时,我想知道它是从数组A或数组B中获取的。

How can I do that? 我怎样才能做到这一点?

Should I use dictionary instead of Array? 我应该使用字典而不是数组吗?

Yes , you should use Dictionary instead of Array . 是的 ,您应该使用Dictionary而不是Array Set the Array as an Object with the Key as ArrayName . 键设置ArrayName,Array设置为对象

Sample Code : 样例代码:

NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:arrayA,@"ArrayA",arrayB,@"ArrayB", nil];
NSLog(@"dict :: %@",dict);

Update : 更新:

To display the title & id in the TableView cell : 要在TableView单元格中显示标题ID

yourTitleLabel.text = [[[dict objectForKey:@"ArrayA"] objectAtIndex:indexPath.row] objectForKey:@"title"];
yourIdLabel.text = [[[dict objectForKey:@"ArrayA"] objectAtIndex:indexPath.row] objectForKey:@"id"];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM