How to bring list of buttons when button pressed in iOS app

南笙酒味 提交于 2020-01-05 06:52:28

问题


I don't know what to search for or what it is called, as I am totally new. Please help me that when I press button it will show other button. We found it in lot of apps, but I don't know the name.. I attached its picture below. How can I do this in an iOS app.


回答1:


Is called UIActionSheet.

And here is a rater complex example:

    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];



回答2:


Go through the UIActionsheet. Do additons like this

// in .h class

@interface MyViewController : UIViewController <UIActionSheetDelegate> {

    ...

}


...


-(IBAction)showActionSheet:(id)sender;

@end

In .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;
        }
        */
    }


来源:https://stackoverflow.com/questions/14273939/how-to-bring-list-of-buttons-when-button-pressed-in-ios-app

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!