iOS iPad UIActionSheet Issue
Posted
by
hart1994
on Stack Overflow
See other posts from Stack Overflow
or by hart1994
Published on 2012-06-09T22:36:35Z
Indexed on
2012/06/09
22:40 UTC
Read the original article
Hit count: 495
I am currently developing an application which needs an option to 'share' using multiple services; such as email, twitter.
To to this, I have a UIBarButtonItem
coded in and when touched, it triggers this:
UIActionSheet *sheet = [[UIActionSheet alloc]
initWithTitle:@""
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
[sheet addButtonWithTitle:@"Email"];
[sheet addButtonWithTitle:@"Tweet"];
[sheet addButtonWithTitle:@"Cancel"];
sheet.cancelButtonIndex = sheet.numberOfButtons-1;
[sheet showFromRect:self.view.bounds inView:self.view animated:YES];
[sheet release];
In conjunction with this to detect which button is selected:
clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == actionSheet.cancelButtonIndex) { return; }
switch (buttonIndex) {
case 0:
{
[self emailThis];
break;
}
case 1:
{
[self tweetThis];
break;
}
}
This works a treat on the iPhone. But unfortunately it displays incorrectly on the iPad. It looks like it is trying to display the UIPopoverController
, but it is positioned center of the navbar with practically no height.
I have looked into using the UIPopoverController, but I cannot seem to find out how to use it with buttons. Is there anyway I can adapt the code above to properly display the buttons, as it's trying to already.
Many thanks,
Ryan
PS: I'm new to objective-c/iOS coding, so please be specific. Thank you :)
© Stack Overflow or respective owner