To show the UIActionSheet, instance UIActionSheet and show it with this piece of code.
UIActionSheet *popupQuery = [[UIActionSheet alloc] initWithTitle:@"Share" delegate:self cancelButtonTitle:@"Cancelar" destructiveButtonTitle:nil otherButtonTitles:@"Facebook", @"Twiter", @"E-mail", nil];
popupQuery.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[popupQuery showInView:self.view];
[popupQuery release];
Cancel button will hide our action sheet when is pushed, destructive button will appear in red background and any other button will appears as normal. Both, destructive and the other buttons behaviour has to be declared implementing UIActionSheetDelegate clickedButtonAtIndex.
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
NSLog(@"Button Facebook clicked");
} else if (buttonIndex == 1) {
NSLog(@"Button Twitter clicked");;
} else if (buttonIndex == 2) {
NSLog(@"Button Email clicked");
}
}
With this piece of code you can implement a context menu like behaviour in your view. Take note that you have not to implement cancel button index click behaviour.
I hope this code snippet helps you, enjoy it!!!
No comments:
Post a Comment