Having problems with adding objects to NSMutableArray

﹥>﹥吖頭↗ 提交于 2019-12-02 11:43:18

First off, you're over-retaining the array.

Second, you didn't provide the code for initializing the array, so I guess it's not allocated and initialized. This will cause the code to message a nil object and thus return nil.

You should create an init method for the Controller object, and allocate a new NSMutableArray object (and retain it).

Also, a proper dealloc to release the array.

NSMutabaleArray starts at index 0

Here is the method I added to Controller class:

- (id)init {
    self = [super init];
    if(self){
        array = [[NSMutableArray alloc] init];
    }
    return self;
}
- (void)dealloc {
    [array release];
    [super dealloc];
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!