EXC_BAD_ACCESS when not using self.

Posted by chris on Stack Overflow See other posts from Stack Overflow or by chris
Published on 2010-03-25T04:59:14Z Indexed on 2010/03/25 5:03 UTC
Read the original article Hit count: 292

Filed under:

I got nabbed by the following bug again and would like some clarification to exactly why it is a bug.

I have a simple UITableView that loads some data:

// myclass.h
@property (nonatomic, retain) NSArray *myData

// myclass.m
@synthesize myData;

- (void) viewDidLoad {
  ...
  myData = someDataSource // note the lack of self
}

- (UITableViewCell *) cellForRowAtIndexPath ... {
   ...
   cell.textLabel.text = [self.myData objectAtIndex:indexPath.row];  // EXC_BAD_ACCESS
}

The table first loads fine, but when scrolling up enough that one of the cells is totally out of the view I then get the EXC_BAD_ACCESS error.

Am I missing something in regards to @property retain. My understanding is that it releases anything that the pointer was previously pointing to before the reassignment. If I am correct then why would not using self. cause any problems?

Thanks for the help.

© Stack Overflow or respective owner

Related posts about iphone