开发者

I can not addObject to NSMutableArray initializedWith 5 string objects

NSMutableArray *array = [[NSArray alloc] initWithObjects:@"Apranax Forte",
             开发者_JAVA百科                                            @"Actified",
                                                         @"Zostex 125 MG",
                                                         @"Zoprotec 30 MG",
                                                         @"Arveles 25 MG"];

[array insertObject:@"Ahmet" atIndex:[array count] + 1]; // Neither work
[array addObject:@"Ahmet"]

I want to append the Ahmet string to the NSMutableArray array object ... Can anyone help me ?


You're not instaniating a mutable array:

[[NSMutableArray alloc] initWithObjects:@"Apranax Forte",
                                        @"Actified",
                                        @"Zostex 125 MG",
                                        @"Zoprotec 30 MG",
                                        @"Arveles 25 MG",
                                        nil];

Also don't forget to terminate the collection of objects with nil.


make sure that you terminate your array with "nil"

NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:@"Apranax Forte",     @"Actified",@"Zostex 125 MG",@"Zoprotec 30 MG",@"Arveles 25 MG", nil];


You need to change [NSArray alloc] to [NSMutableArray alloc]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜