Take the 2-minute tour ×

So this is the set up of my app. In my view did load method, I create an NSMutableArray, and I initialize it with a list of object (using the initWithObjects: method). This array get's loaded into a table view without any problems. I've also added a "+" button in the navigation bar to add data to my table. My problem is that every time I press this "+" my app freezes and I get the SIGABRT signal. Can someone tell me what I'm doing wrong?

I've retained the array using a property, and I've synthesized it. I'm also releasing it in the dealloc method.

I'm creating the array like this:

NSMutableArray *array = [[NSArray alloc] initWithObjects:@"data 1", @"data 2", @"data 3", nil];
self.myArray = array;
[array release];

I'm creating the "+" button in the nav bar with this:

UIBarButtonItem *addDataButton = [[UIBarButtonItem alloc] initWithTitle:@"+" 

My method for adding data is:

- (void)addData {

    [myArray addObject:@"some data"];
    [self.tableView reloadData];


Also if this helps at all, the error message I get in the console is this:

2011-02-19 13:02:09.987 MyApp[480:307] -[__NSArrayI addObject:]: unrecognized selector sent to instance 0x1bee50
2011-02-19 13:02:10.020 MyApp[480:307] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI addObject:]: unrecognized selector sent to instance 0x1bee50'
share|improve this question
could you post code where you create myArray - it looks like it is not NSMutableArray, but NSArray for some reason –  Vladimir Feb 19 '11 at 20:22
add comment

1 Answer

up vote 2 down vote accepted

You're creating an NSArray and not an NSMutableArray and so you can't add objects to it. Change the array initialization to:

NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:@"data 1", @"data 2", @"data 3", nil];
share|improve this answer
perfect that was exactly my problem. I can't believe I missed that. Thank you. –  cgossain Feb 19 '11 at 20:33
add comment

Your Answer


