Wednesday, October 21, 2009

iPhone dev Stupidity 82: change the title of "back" button in nav

From stackoverflow: you gonna change it in parent view controller - the one just under the stack.

// set the category


// .. get parent


NSArray * viewControllerArray = [self.navigationController viewControllers];


int parentViewControllerIndex = [viewControllerArray count] - 2;


UIViewController * parent_vc = [viewControllerArray objectAtIndex: parentViewControllerIndex];



// .. if the category changed


if(![parent_vc.navigationItem.backBarButtonItem.title isEqualToString: cat_name]){


 // update the back button title


 UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle: cat_name style: UIBarButtonItemStyleBordered target: nil action: nil];


 parent_vc.navigationItem.backBarButtonItem = newBackButton;


 [newBackButton release];

}


No comments: