在類中申明UIActionSheet對象,若是須要處理選擇UIActionSheet項後的消息,則須要使用UIActionSheetDelegate。 .net
@interface MyClassController : UIViewController <UIActionSheetDelegate> { UIActionSheet *sheet; } @end建立和顯示UIActionSheet
sheet = [[UIActionSheet alloc] initWithTitle:@"Select Belgian Beer Style" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Dubble", @"Lambic", @"Quadrupel", @"Strong Dark Ale", @"Tripel", nil]; // Show the sheet [sheet showInView:self.view]; [sheet release];
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex { NSLog(@"Button %d", buttonIndex); }