Move Cancel Button from top to bottom
In .h: include UIAlertViewDelegate
@interface MyController : UIViewController <UIAlertViewDelegate> {
}
In .m: implement delegates
- (void) ShowActionSheet:(NSString *)title {
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:title
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles: nil];
[actionSheet addButtonWithTitle:@"Option 1"];
[actionSheet addButtonWithTitle:@"Option 2"];
[actionSheet addButtonWithTitle:@"Option 3"];
[actionSheet addButtonWithTitle:@"Cancel"];
actionSheet.cancelButtonIndex = actionSheet.numberOfButtons;
[actionSheet showInView:self.view];
[actionSheet release];
}
- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
NSLog(@"title=%@, buttonIndex: %d, cancelButtonIndex: %d, firstOtherButtonIndex: %d",
actionSheet.title,
buttonIndex,
actionSheet.cancelButtonIndex,
actionSheet.firstOtherButtonIndex);
}
沒有留言:
張貼留言