teepusink
teepusink

Reputation: 28892

Objective C - UITableViewCell crashing on scroll

I have a UITableViewCell with a method like this.

-(void) setupStore:(StoreModel *) store {
    self.title.text = store.title; // crash here when scrolling
}

So that method is called from within a UIViewController class that contains the UITableView.
Something like this

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ...
    [cell setupStore:[storesArray objectAtIndex:indexPath.row]];
    ...
}

That works when the table first loaded, but when I scroll the table, it crash with error EXC_BAD_ACCESS.

What could be causing that?

Please enlight.

Thanks,
Tee

Upvotes: 0

Views: 169

Answers (2)

Harshini Nerella
Harshini Nerella

Reputation: 99

In general We will get EXC_BAD_ACCESS when we are trying to use a released object.

So you can check whether you are using any released object.

As you have mentioned that storesArray = [[[storesLocation alloc] init]retain]; there is no need to retain the object. Give a try by using this line

storesArray = [[storesLocation alloc] init];.

Also make sure that storemodel object exists by logging it in this method

-(void) setupStore:(StoreModel *) store
{
   NSLog(@"store model %@",store);
}
You can go through the link

https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmPractical.html

Upvotes: 0

vikingosegundo
vikingosegundo

Reputation: 52227

Try to build your code with NSZombieEnabled = YES and report here what is happening. Give us the full error description.

http://cocoa-nut.de/?p=16

Upvotes: 1

Related Questions