Question

I have an interesting problem, and I can't seem to find out why it is happening, might be something small that I am overlooking.

I have a UITableView and in my didselectrowatindex path I navigate to a new view, I then navigate to the next view and pop both views to get back to the first and then the app crashes with the EXC_BAD_ACCESS

So I used instruments and NSZombie and found a malloc in didselectrowatindexpath, but I have no idea why

Here is my code:

if([workflowswithdirectories count] == 0)
{
    WorkflowViewController *aWorkFlow = [[WorkflowViewController alloc] init];
    MenuObject *obj = [workflownames objectAtIndex:[indexPath row]];
    aWorkFlow.heading = obj.name;
    aWorkFlow.workId = obj.workflowid;
    aWorkFlow.siteId = obj.siteid;
    aWorkFlow.item = obj;
    [self.navigationController pushViewController:aWorkFlow animated:YES];

}
else if([workflownames count] == 0)
{
    WorkflowListViewController *work = [[WorkflowListViewController alloc] init];
    work.siteId = self.siteId;
    MenuObject *obj = [workflowswithdirectories objectAtIndex:[indexPath row]];
    work.menu = obj.next;
    work.heading = obj.name;
    [self.navigationController pushViewController:work animated:YES];
}
else
{
    if([indexPath section] == 0)
    {
        WorkflowListViewController *work = [[WorkflowListViewController alloc] init];
        work.siteId = self.siteId;
        MenuObject *obj = [workflowswithdirectories objectAtIndex:[indexPath row]];
        work.menu = obj.next;
        work.heading = obj.name;
        [self.navigationController pushViewController:work animated:YES];
    }
    else
    {
        WorkflowViewController *aWorkFlow = [[WorkflowViewController alloc] init];
        MenuObject *obj = [workflownames objectAtIndex:[indexPath row]];
        aWorkFlow.heading = obj.name;
        aWorkFlow.workId = obj.workflowid;
        aWorkFlow.siteId = obj.siteid;
        aWorkFlow.item = obj;
        [self.navigationController pushViewController:aWorkFlow animated:YES];  //Malloc is on this line
    }
}  
[tableView deselectRowAtIndexPath:indexPath animated:YES];

EDIT:

Something I forgot to mention is, in certain cases I push another one of this same class onto the navigationcontroller, but it is only when going to the WorkflowViewController and then to the next viewcontroller and then back twice that the exception is thrown

Was it helpful?

Solution

For memory and efficiency's sake, make all UIViewControllers strong properties (with a backing iVar) to guarantee they stay around long enough for anything useful.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top