Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Buttons on top of UIPopoverController

I want to add two Buttons on top of UIPopoverController like it is shown in following screenshots: HTML Edit

Thanks for helping me!

like image 924
Pascal Bayer Avatar asked May 13 '10 15:05

Pascal Bayer


3 Answers

Add your view controller to a UINavigationController, then add the Navigation Controller to the UIPopoverController. Then in your UIViewController's viewDidLoad method, put this code in:

UIBarButtonItem *okButton = [[UIBarButtonItem alloc] initWithTitle:@"Ok" style:UIBarButtonItemStyleBordered target:self action:@selector(okayButtonPressed)];
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelButtonPressed)];

self.navigationItem.title = @"My Title";

[self.navigationItem setLeftBarButtonItem:cancelButton animated:NO];
[self.navigationItem setRightBarButtonItem:okButton animated:NO];

[cancelButton release];
[okButton release];
like image 157
David Avatar answered Oct 18 '22 02:10

David


You need to initialize your popover with a UINavigationController directly. Then set the root view to your custom view controller.

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:yourViewController];     
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:navigationController];
like image 34
Jer K. Avatar answered Oct 18 '22 02:10

Jer K.


Use a UINavigationController as the pop-over. Then, access the .navigationBar property of the navigation controller, get the .topItem, and set its .leftBarButtonItem and .rightBarButtonItem.

like image 5
kennytm Avatar answered Oct 18 '22 02:10

kennytm