0

i know that this is basic objective C question but I have serious problems. I am having an NSMutable array which I fill with values in my connectionDidFinishLoading. i can see in NSLog that values are being assigned correctly. But when i am trying to fetch these values in DidSelectRow (as I am using a table view I get a BAD_ACESS error)

Here is my code:

@implementation MainMap
{

    NSMutableArray *condition ;
}
..
- (void)viewDidLoad
{
    [super viewDidLoad];
}
...
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
condition= [NSMutableArray array];
..adding objects..
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    //app crashes in here
NSLog(@"Condition of pressed item is %@",[condition objectAtIndex:indexPath.row]);
}

If I place the condition= [NSMutableArray array]; inside ViewDidLoad I get a SIGBART.

Moreover I tried to place the declarations in .h file and have it as property and then synthesize it in .m but still nothing. Maybe I am missing something, so can you fix it?

2
  • Do you use ARC in this project? Commented Sep 9, 2012 at 19:24
  • 1
    Then NSAutoreleasePool has destroyed your data. I see that you already got good answer. Have a nice day. Commented Sep 9, 2012 at 19:42

1 Answer 1

2

Just try [NSMutableArray new] instead [NSMutableArray array]. Then you should release condition in your dealloc-method.

Otherwise you can enable ARC (http://longweekendmobile.com/2011/09/07/objc-automatic-reference-counting-in-xcode-explained/). With ARC you must not handle reference counting by yourself.

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.