Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
Status
Not open for further replies.

RagingGoat

macrumors 6502
Original poster
Jun 21, 2010
308
15
I have a split view app which I started with the master-detail template. The problem I'm having is that WHen I select a row from my master view and have a new view show in the detail view, the navigation controller is showing up and I don't want it to be there on the new view. The new detail view should just have a navigation bar that I've added to it with a button for an activity view controller. The button shows up under the nav bar for the navigation controller but my nav bar doesn't show up. The reason I don't want the navigation controller is because once a row in the master view is selected and the new detail view shows up, the back button has to be pressed in order to select another row from the master view. Basically, I'm just wanting to replace the detail view with a new one. How can I get this working like I want it?

From didSelectRowAtIndexPath:

Code:
NSMutableArray *details = [self.splitViewController.viewControllers mutableCopy];
    
    [details replaceObjectAtIndex:1 withObject:webViewController];
    
    [[self.splitViewController.viewControllers lastObject] pushViewController:details.lastObject animated:YES];
 

Attachments

  • iOS Simulator Screen shot Jun 8, 2013 3.22.17 PM.png
    iOS Simulator Screen shot Jun 8, 2013 3.22.17 PM.png
    1 MB · Views: 194
From didSelectRowAtIndexPath:

Code:
NSMutableArray *details = [self.splitViewController.viewControllers mutableCopy];
    
    [details replaceObjectAtIndex:1 withObject:webViewController];
    
    [[self.splitViewController.viewControllers lastObject] pushViewController:details.lastObject animated:YES];

As I read it your code is 3 lines could be just this one.
Code:
[[self.splitViewController.viewControllers lastObject] pushViewController:webViewController animated:YES];

If you push a veiwController on to a navigation stack it wants to make the navigation bar visible and put a back button on to it.

To get what you want you need to either replace the rootViewController of the stack or make your webViewController part of the detailViewController of the splitView then have a way to set the web address in your didSelectRowAtIndexpath: method.
 
in my didFinishLaunchingWithOptions method:

Code:
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
    {
        KFBViewController *rootView = [[KFBViewController alloc] initWithNibName:@"KFBViewController" bundle:nil];
        
        KFBNavControllerViewController *navController = [[KFBNavControllerViewController alloc] initWithRootViewController:rootView];
        navController.delegate = rootView;
        
        UIViewController *aboutUs = [[AboutUs alloc] initWithNibName:@"AboutUs" bundle:nil];
        KFBNavControllerViewController *navController1 = [[KFBNavControllerViewController alloc] initWithRootViewController:aboutUs];
        
        UIViewController *contactUs = [[ContactUs alloc] initWithNibName:@"ContactUs" bundle:nil];
        KFBNavControllerViewController *navController2 = [[KFBNavControllerViewController alloc] initWithRootViewController:contactUs];
        
        UIViewController *kyfb = [[KYFB alloc] initWithNibName:@"KYFB" bundle:nil];
        KFBNavControllerViewController *navController3 = [[KFBNavControllerViewController alloc] initWithRootViewController:kyfb];
        
        self.tabBarController = [[KFBTabBarViewController alloc] init];
        self.tabBarController.viewControllers = @[navController, navController1, navController2, navController3];
        
        self.viewController = [[KFBViewController alloc] initWithNibName:@"KFBViewController" bundle:nil];
        self.window.rootViewController = self.tabBarController;
    }
    else
    {
        KFBMasterViewController *masterViewController = [[KFBMasterViewController alloc] initWithNibName:@"KFBMasterViewController_iPad" bundle:nil];
        UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
        
        KFBDetailViewController *detailViewController = [[KFBDetailViewController alloc] initWithNibName:@"KFBDetailViewController_iPad" bundle:nil];
        UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
    	
    	masterViewController.detailViewController = detailViewController;
    	
        self.splitViewController = [[UISplitViewController alloc] init];
        self.splitViewController.delegate = detailViewController;
        self.splitViewController.viewControllers = @[masterNavigationController, detailNavigationController];
        
        self.window.rootViewController = self.splitViewController;
    }
    [self.window makeKeyAndVisible];
    return YES;


These lines in my didSelectRowAtIndexPath replace the second item in the array with the webViewController

Code:
NSMutableArray *details = [self.splitViewController.viewControllers mutableCopy];
    
    [details replaceObjectAtIndex:1 withObject:webViewController];
    
    [[self.splitViewController.viewControllers lastObject] pushViewController:details.lastObject animated:YES];

The app works like this: A default master table view and detail view are loaded when the app is launched. When a row in the master view is selected, another table view shows up in the master view. A row is then selected from that seconds table view and the webViewController replaces whatever detail view is there. The issue with this is the navigation controller. When a row is selected from the second table view and the web view shows as the detail view, it is just getting added to the detail nav stack so in order to select another row from master view, the back button on the detail nav controller has to be pressed. I don't want that back button. I want the webViewController to be the only thing in the detail view stack.
 
I've almost got it working correctly. The only problem now is that there is no button on the detail view nav bar to show the master view when in portrait. Is this just something I will need to add myself?

My didSelectRowAtIndexPath now looks like this:

Code:
NSMutableArray *details = [self.splitViewController.viewControllers mutableCopy];
    
    UINavigationController *detailNav = [[UINavigationController alloc]initWithRootViewController:webViewController];
    
    [details replaceObjectAtIndex:1 withObject:detailNav];
    
    self.splitViewController.viewControllers = details;
    
    KFBAppDelegate *appDelegate = (KFBAppDelegate *)[[UIApplication sharedApplication]delegate];
    appDelegate.window.rootViewController = self.splitViewController;
 
Status
Not open for further replies.
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.