views:

39

answers:

2

Hi all,

I've got a view containing a segmentedControl and a tableView. The tableView is populated depending on the segmentedControl item that is selected (in this case Food and wine). The data for the tableView is generated from coreData.

It works fine when starting up the application which any of the segmentedControl items selected (food or wine) and is displaying the right data. But as soon as I try to select the other item the app crashes saying "Program received signal: “EXC_BAD_ACCESS”.". Sadly the debugger does not give me any legible information to know where the exception happens, so I inserted breakpoints and it seems to happen in

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

MenuSubsections* menuSubsection = [self.menuSubsections objectAtIndex:section];
if (![menuSubsection menuItems]) {
    return 0;
}

return [[menuSubsection menuItems] count];
}

in the last line.

I inserted a NSLog for menuSubsection and it says, among other stuff that is right,

menuItems = "<relationship fault: 0x8133540 'menuItems'>";

But it also gives the same message when starting up and working fine...

Any idea?

Thanks,
Miguel

A: 

To make life easier after a crash, you can try this

taskinoor
I will check that out, thanks :-)
Michi
A: 

It looks like you've in effect two logical tables being displayed in a single table. When you choose one segmented control or the other you're swapping out the entities, Food or Wine, displayed by the table.

This is fine but each entity will have its own data structure that defines it's own version of the table and you have to make sure you return the proper number of sections and rows for the currently selected entity. It is unlikely that there is exactly the same number of Food entities as Wine entities

It looks like your MenuSubsections class only returns the count of rows for a section for one of the entities. When you switch to the other entity it keeps returning the row count for the first entity which causes the table to access objects for rows that don't exist which causes the crash.

Your numberOfRowsInSection: method needs an additional layer of logic such that it checks the value of the segmented control and then returns the right MenuSubsections for either Food or Wine.

TechZen
Hi TechZen, Sorry for not updating this question before as I already solved it. The problem were that I was releasing a property that still was in use. I will accept your answer anyway so other people can see it.
Michi