0

I created a pop over to view my settings like this,

if ([popoverController isPopoverVisible]) {
    [popoverController
     dismissPopoverAnimated:YES];
} else {

    UIView* popoverView = [[UIView alloc]
                           initWithFrame:CGRectMake(566, 440, 0, 0)];

    popoverView.backgroundColor = [UIColor blackColor];
    controller1.contentSizeForViewInPopover = CGSizeMake(300, 115);

    popoverController = [[UIPopoverController alloc]
                         initWithContentViewController:controller1];


    [popoverController presentPopoverFromRect:popoverView.frame
                                       inView:self.view
                     permittedArrowDirections:UIPopoverArrowDirectionUp
                                     animated:YES];
}

my push action code:

UIStoryboard *storyboard = [UIStoryboard
                            storyboardWithName:@"MainStoryboard"
                            bundle:nil];

UIViewController *controller = (UIViewController *)[storyboard
                                                    instantiateViewControllerWithIdentifier:@"PCBViewController"];

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

In my settings popover has some buttons. Those button is clicked, view controller open through push action but its not working.

My Question is: How to set push action for popover contents.

Shankar
  • 51
  • 1
  • 8

2 Answers2

1

Your view is presented from popover thus self.navigationController will be nil.

Try this

UIStoryboard *storyboard = [UIStoryboard
                            storyboardWithName:@"MainStoryboard"
                            bundle:nil];

UIViewController *controller = (UIViewController *)[storyboard
                                                    instantiateViewControllerWithIdentifier:@"PCBViewController"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:controller];
[navigationController
 pushViewController:controller
 animated:YES];
βhargavḯ
  • 9,786
  • 1
  • 37
  • 59
  • i tried but i got these error 2013-11-19 10:20:22.604 CoinsAndBills_aus[1699:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing the same view controller instance more than once is not supported ()' *** First throw call stack: – Shankar Nov 19 '13 at 04:51
  • I guess the view you are pushing already exists in navigation stack. You should pop view from navigation stack if it is no longer used. – βhargavḯ Nov 19 '13 at 04:53
  • look http://stackoverflow.com/questions/10281545/removing-viewcontrollers-from-navigation-stack – βhargavḯ Nov 19 '13 at 05:04
0

you need to set up navigation controller for the view controller to allow navigation.

in your .h file

UINavigationController *navevent;
UIViewController *yourViewController

in .m file synthasize it and in view did load

 navevent=[[UINavigationController alloc]initWithRootViewController:yourViewController];
 yourViewController=[[UIViewController alloc]init];

then create your popover like this

yourViewController.view = yourView;
 self.popoverController = [[UIPopoverController alloc]initWithContentViewController:navevent] ;

hope this help

wasim
  • 698
  • 8
  • 20