NCFUSN
NCFUSN

Reputation: 1654

NavigationController issue in non rootViewController view

Finally yesterday I've got my UISearchBar working properly. Suddenly now I am facing another issue.

When I navigate through the views, the navigation bar moves to the right and the same navigation bar appears again -> same title and navigation button on the left. TableView stays unmoved. On the second click on navigation button, it yes, returns to the previous View.

The annotation I am getting is: Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.

I've browsed the related issues in this forum, but it didn't help me.

- (void)viewDidUnload
{
   [self setTableView:nil];
   [super viewDidUnload];
   [self setSearchController:nil];
   [self setSearchBar:nil];
}

- (void)tableView:(UITableView *)atableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
Kings *kingsObj;

if(atableView==self.tableView)
{
    kingsObj=[self.kingsArr objectAtIndex:[indexPath row]];
    Items *items=[[Items alloc]initWithNibName:@"Items" bundle:nil];
    items.kingID=kingsObj.kingID;
    items.king=kingsObj.kingName;
    [self.navigationController pushViewController:items animated:YES];
    [items release];
}
else
{
    kingsObj=[self.filteredItems objectAtIndex:[indexPath row]];
}

Items *items=[[Items alloc]initWithNibName:@"Items" bundle:nil];
items.kingID=kingsObj.kingID;
items.king=kingsObj.kingName;
[self.navigationController pushViewController:items animated:YES];
[items release];
}

Ok. the pushViewController method is inside the didSelectRowAtIndexPath. What can be wrong with it now? Before it was doing well.

Upvotes: 0

Views: 223

Answers (3)

jonkroll
jonkroll

Reputation: 15722

The error is because you are pushing a new ViewController twice. You can simplify your didSelectRowAtIndexPath code like this:

- (void)tableView:(UITableView *)atableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
    Kings *kingsObj; 
    if (atableView==self.tableView) {
        kingsObj = [self.kingsArr objectAtIndex:[indexPath row]];
    } else {
        kingsObj = [self.filteredItems objectAtIndex:[indexPath row]];
    }

    Items *items=[[Items alloc]initWithNibName:@"Items" bundle:nil];
    items.kingID=kingsObj.kingID;
    items.king=kingsObj.kingName;
    [self.navigationController pushViewController:items animated:YES];
    [items release];
}

Upvotes: 1

Vincent Bernier
Vincent Bernier

Reputation: 8664

You are doing something twice.

[self.navigationController pushViewController:items animated:YES];

Get call if this line is YES

if(atableView==self.tableView)

Then it get call again later in the method (after the else statement (check for your {})
This is how you end up with your :

Navigation Bar subview tree might get corrupted.

Upvotes: 0

Rob
Rob

Reputation: 4239

Are you programming iOS5? If you are then you may be over releasing you view controller "Items". If you have ARC (Automatic Reference Counting) turned on, the code will release the object for you at the right time. If you also release it you are probably pushing a view controller on the stack which goes away while the Navigation Controller is trying to work with it. That would cause an unstable condition.

Try removing you [items release] statements and see if that helps.

Rob

Upvotes: 0

Related Questions