PushViewController Not Working in Popover

Discussion in 'iOS Programming' started by ahan.tm, Mar 27, 2012.

  1. ahan.tm macrumors regular

    Joined:
    Jun 26, 2011
    Location:
    Florida
    #1
    Hi,

    I ny Universal project, I create a popover using the following code:
    Code:
    FlipsideViewController *controller = [[[FlipsideViewController alloc] initWithNibName:@"FlipsideViewController" bundle:nil] autorelease];
        controller.delegate = self;
        
        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
        
        
        
        
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
            NSLog(@"iPhone");
            
            
            navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
            [self presentModalViewController:navController animated:YES];
            
            [navController release];
            [controller release];
        } else {
            if (!self.flipsidePopoverController) {
                
                NSLog(@"iPad");
                
                        
                self.flipsidePopoverController = [[[UIPopoverController alloc] initWithContentViewController:navController] autorelease];
            }
            if ([self.flipsidePopoverController isPopoverVisible]) {
                
                [self.flipsidePopoverController dismissPopoverAnimated:YES];
            } else {
                [self.flipsidePopoverController presentPopoverFromRect:[info bounds] inView:info permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
            }
        }
    
    This code occurs when an info button is pressed on my MainViewController.

    Now, In my FlipsideViewController, I need to get the navigation controller to push the "DetailViewController" when an object is selected on the table view.

    This is the code I am using:
    Code:
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    	
        // Create and push a detail view controller.
    	DetailViewController *detailViewController = [[DetailViewController alloc] initWithStyle:UITableViewStyleGrouped];
        Child *selectedChild = (Child *)[[self fetchedResultsController] objectAtIndexPath:indexPath];
        // Pass the selected book to the new view controller.
        detailViewController.child = selectedChild;
        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
        self.contentSizeForViewInPopover = CGSizeMake(320.0, 480.0);
        
        
        MainViewController *sharedData = [MainViewController sharedMainViewController];
        
        
        
        [self.navigationController pushViewController:detailViewController animated:YES];
    }
    However, when I select an object on the table view, the animation occurs, but just to a plain blue screen with the navigation controller. Why is pushViewController not changing the view, only the navigation controller?

    Thanks,
    ahan.tm:)
     
  2. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    It seems that you have more than one navigation controller and you're pushing the new view controller onto the wrong one.

    You normally create a navigation controller with a new view controller as its root view controller and you add the navigation controller to the popover controller as its content view controller. You can later push more view controllers onto the navigation controller in the popover if you want.
     
  3. ahan.tm thread starter macrumors regular

    Joined:
    Jun 26, 2011
    Location:
    Florida
    #3
    Forgot to mention: Pushing a view controller works on the iPhone!

    Anyway, Should I initialize the new view in a different way in my mainViewController, or should I use a singleton to change the navigation controller?

    Thanks
     
  4. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #4
    Of course you have no popovers on iPhone.

    Read again what I wrote above. You need to present the new view controller using the correct popover and navigation controller.
     
  5. ahan.tm thread starter macrumors regular

    Joined:
    Jun 26, 2011
    Location:
    Florida
    #5
    But, there are 2 different files:

    MainViewController-- Main view in which the popover is initialized and does NOT use a navigation controller.

    FlipsideViewController-- Flipside View that appears in the popover and uses a navigation controller.

    Should I initialize the navigation controller inside FlipsideViewController instead MainViewController?
     

Share This Page