将字符串添加到二维数组

时间:2010-10-08 06:52:10

标签: iphone

如何将对象添加到二维数组?该数组由几个项目启动(见下文),但我需要向数组中添加更多项目。

      images_ = [[NSArray alloc] initWithObjects:
             [NSArray arrayWithObjects:@"http://farm3.static.flickr.com/2735/4430131154_95212b8e88_o.jpg", @"http://farm3.static.flickr.com/2735/4430131154_17d8a02b8c_s.jpg", nil],
             [NSArray arrayWithObjects:@"http://farm5.static.flickr.com/4001/4439826859_19ba9a6cfa_o.jpg", @"http://farm5.static.flickr.com/4001/4439826859_4215c01a16_s.jpg", nil],nil];

2 个答案:

答案 0 :(得分:1)

简单回答,添加更多项目;)

我不知道这是什么问题?

编辑:

哦,我知道,如果你想稍后添加对象,你需要一个NSMutableArray!

答案 1 :(得分:0)

这样的事情:

NSMutableArray *firstSubArray = [[NSMutableArray arrayWithObjects:@"http://farm3.static.flickr.com/2735/4430131154_95212b8e88_o.jpg", @"http://farm3.static.flickr.com/2735/4430131154_17d8a02b8c_s.jpg", nil] retain];

NSMutableArray *secondSubArray = [[NSMutableArray arrayWithObjects:@"http://farm5.static.flickr.com/4001/4439826859_19ba9a6cfa_o.jpg", @"http://farm5.static.flickr.com/4001/4439826859_4215c01a16_s.jpg", nil] retain];

images_ = [[NSArray alloc] initWithObjects: firstSubArray, secondSubArray ,nil];

[secondSubArray addObject: @"New string"]