如何在iOS应用程序中按下button时列出button
我不知道要search什么或叫什么,因为我是全新的。 请帮我,当我按下button时,会显示其他button。 我们在很多应用程序中发现它,但是我不知道名称。我在下面附上它的图片。 我怎样才能在iOS应用程序中做到这一点。
被称为UIActionSheet
。
这里是一个比较复杂的例子:
UIActionSheet *actionSheet = [[UIActionSheet alloc] init] ; actionSheet.title = @"Change pincode?"; actionSheet.delegate = self; actionSheet.tag = kChangePincode; [actionSheet addButtonWithTitle:@"Chacge pincode"]; [actionSheet addButtonWithTitle:@"Remove pin code"]; [actionSheet addButtonWithTitle:@"cancel"]; [actionSheet setCancelButtonIndex:(actionSheet.numberOfButtons - 1)]; [actionSheet showInView:self.view];
通过UIActionsheet。 做这样的附加
//在.h类中
@interface MyViewController : UIViewController <UIActionSheetDelegate> { ... } ... -(IBAction)showActionSheet:(id)sender;
@结束
在.m
-(IBAction)showActionSheet:(id)sender { UIActionSheet *popupQuery = [[UIActionSheet alloc] initWithTitle:@"Title" delegate:self cancelButtonTitle:@"Cancel Button" destructiveButtonTitle:@"Destructive Button" otherButtonTitles:@"Other Button 1", @"Other Button 2", nil]; popupQuery.actionSheetStyle = UIActionSheetStyleBlackOpaque; [popupQuery showInView:self.view]; [popupQuery release]; } // Handle Delegates------------- -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { if (buttonIndex == 0) { self.label.text = @"Destructive Button Clicked"; } else if (buttonIndex == 1) { self.label.text = @"Other Button 1 Clicked"; } else if (buttonIndex == 2) { self.label.text = @"Other Button 2 Clicked"; } else if (buttonIndex == 3) { self.label.text = @"Cancel Button Clicked"; } /** * OR use the following switch statement * */ /* switch (buttonIndex) { case 0: self.label.text = @"Destructive Button Clicked"; break; case 1: self.label.text = @"Other Button 1 Clicked"; break; case 2: self.label.text = @"Other Button 2 Clicked"; break; case 3: self.label.text = @"Cancel Button Clicked"; break; } */ }