I am buiding a Right to Left navigation controller to support RTL Languages. After reading some posts in StackOverFlow Push ViewController from Right To Left with UINavigationCo
Inspired by the solutions from @locke I rewrote the code as follows:
1- Define a UIViewController in the appdelegate called preViewController to hold the master view controller.
2- To reference it in the view controllers use the:
AppDelegate *appdelegate=(AppDelegate *)[[UIApplication sharedApplication] delegate];
3- write the following masterviewcontroller as follows:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//create a mutable arry to hold the view controllers and copy the current list of navigation controllers
//at this point there is only the current view controller in stack
NSMutableArray *vcs = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];
//create a detailed navigation controller
DetailedViewController *DVC = [[DetailedViewController alloc]initWithNibName:@"DetailedViewController" bundle:nil];
//create a shared variable enviroment to reference a global variable
AppDelegate *appdelegate=(AppDelegate *)[[UIApplication sharedApplication] delegate];
//assign the current viewcontroller to the temporary view controller
appdelegate.preViewController=[self.navigationController.viewControllers lastObject];
//insert detailed view into the array vcs before the current viewcontroller
if (![vcs containsObject:DVC]) {
[vcs insertObject:DVC atIndex:[vcs count]-1];
}
// update the self.navigation with the new stack
[self.navigationController setViewControllers:vcs animated:NO];
// pop the othernavigationcontroller from the navigation stack to fake a detailedview controller push
[self.navigationController popViewControllerAnimated:YES];
}
4 - Add a button to replace the default button and define an IBaction (backClicked) for the detailed view controller:
- (IBAction)backClicked:(id)sender{
AppDelegate *appdelegate=(AppDelegate *)[[UIApplication sharedApplication] delegate];
//push the holder view controller to fake a pop back to the master view controller
[self.navigationController pushViewController:appdelegate.preViewController animated:YES];
}