
I’m wondering how I can create a popover with buttons like this.
ANSWER:
UIActionSheet * actionSheet = [[UIActionSheet alloc] initWithTitle: nil
delegate: self
cancelButtonTitle: nil
destructiveButtonTitle: nil
otherButtonTitles: @"Take Photo",
@"Choose Existing Photo", nil];
[actionSheet showFromRect: button.frame inView: button.superview animated: YES];
Somewhere else in your delegated object class…
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
// take photo...
}
else if (buttonIndex == 1) {
// choose existing photo...
}
}
This is a
UIActionSheet. On the iPhone, it animates in from the bottom. On the iPad it appears in a popover.Assuming you’re doing this on the press of a button:
In iOS8+, you should use the new
UIAlertControllerclass:or in Swift