如何在xcode中创建“删除”操作表?

时间:2011-04-29 06:30:01

标签: ios cocoa-touch uiactionsheet confirmation

如何创建如下所示的删除确认?

4 个答案:

答案 0 :(得分:2)

您需要使用UIActionSheet

您可以像这样创建一个ActionSheet

UIActionSheet *actionSheet = [[UIActionSheet alloc] 
                                initWithTitle:@”YOUR_ACTION_SHEET_TITLE” 
                                delegate:self 
                                cancelButtonTitle:@”Cancel” 
                                destructiveButtonTitle:@”Erase Iphone” 
                                otherButtonTitles:nil];
[actionSheet showInView:self.view];
[actionSheet release];//If you are not using ARC

您需要实施UIActionSheetDelegate方法

- (void)actionSheet:(UIActionSheet *)actionSheet 
            clickedButtonAtIndex:(NSInteger)buttonIndex{

    if (buttonIndex == 0){
       //do your action
    }else if(buttonIndex == 1){
      // do your other action
    }
}

答案 1 :(得分:2)

这是UIActionSheet的一个实例。红色按钮称为“破坏性按钮”,黑色按钮称为“取消按钮”。

这是一个演示:

UIActionSheet *actSheet = [[UIActionSheet alloc] initWithTitle:@"The text to show on top. (Like the message about wiping the phone.)"delegate:nil cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Delete everything" otherButtonTitles:nil];
[actSheet ShowFromToolbar:self.toolbar];
[actSheet release];

答案 2 :(得分:1)

如果您想要与照片中显示的相同以及其他按钮,请使用下面的UIActionSheet blog tutorial,如果您只想要独立按钮,请按照下面的SO帖子

How can I create a big, red UIButton with the iPhone SDK?

答案 3 :(得分:0)

使用Interface Builder(或xCode 4中的等效编辑器)创建视图。编写视图控制器。然后使用Core Animation为视图设置动画以从下方滑入。