1

I am using an NSMutable Array as a datasource to UITableView. I am fetching the values from database and adding it to mutable array. When the view loads I populate the table view with the mutable array and it loads fine. Later when I click a cell it throws an error saying unrecognised selector sent to instance

Inside array I am storing a person object with a name property. I am loading all cells with person.name Later when I try to disolay person.name as the user clicks each cell it shows error. This is how I do

Person *per = (Person*)[my arr objectAtIndex:indexPath.row];
NSlog(@"%@",per.name);

Here it crashes. But I am using the same code inside cellforRowAtIndexPath for displaying the person name.

Sometimes the error says Unrecognised selector name sent to NSArray again sometime it says Unrecognised selector name sent to UIDeviceRGBColor

So it means I am not getting correct object back from my NSMutable Array

How can I do this properly?

Thanks

6
  • can you post some more code ? Commented Feb 8, 2013 at 17:30
  • 1
    Typical memory management error. Check your retain, release, copy, mutableCopy and autorelease messages. Commented Feb 8, 2013 at 17:30
  • 1
    Check if you are retaining the array or not, that is probable. Further more paste the code you are using to initialize the array if it doesn't solves this problem. Commented Feb 8, 2013 at 17:40
  • This looks like an obvious flaw in your logic while maintaining objects in your code. It would be hard to see the error with just a couple of lines of code. Commented Feb 8, 2013 at 17:47
  • I had the same, before, i was free()ing mem, in use. So it's most probably a mem managment problem. Commented Feb 8, 2013 at 17:54

1 Answer 1

1

This is due to the array is dealloacated. Make sure that the array is retained properly. In ARC have a strong reference. In non-ARC make sure you retain the array (I recommend to use property).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.