2

iOS 5 中是否有标准方式来显示此屏幕截图中的删除确认?

如果没有标准的方法,任何解决方案都是好的。

删除确认

4

4 回答 4

12

这是一个UIActionSheet具有破坏性的按钮集。请参阅文档

例如

// Create the action sheet
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil 
                                                   delegate:self 
                                          cancelButtonTitle:@"Cancel" 
                                     destructiveButtonTitle:@"Delete" 
                                         otherButtonTitles:nil];

...

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
    if (buttonIndex == actionSheet.destructiveButtonIndex) {
        // Do the delete
    }
}
于 2012-05-28T16:19:33.637 回答
2

您可以使用 UIActionSheet 如下。

UIActionSheet *actionSheet = [UIActionSheet alloc] initWithTitle:@"Confirm" delegate:aDelegate cancelButtonTitle:nil destructiveButtonTitle:@"Delete" otherButtonTitles:@"Cancel", nil];
[actionSheet showFromRect:aRect inView:aView animated:YES];
于 2012-05-28T16:29:36.163 回答
1

UIActionSheet在 iOS 8 中已弃用。而是使用UIAlertController首选样式UIAlertControllerStyleActionSheet.

// Create a new alert, with an (optional) title and message
UIAlertController* alert = [UIAlertController alertControllerWithTitle:nil
                                                               message:nil
                                                        preferredStyle:UIAlertControllerStyleActionSheet];


// When style is set to UIAlertActionStyleDestructive, the button appears with red text
UIAlertAction* deleteAction = [UIAlertAction actionWithTitle:@"Delete"
                                                       style:UIAlertActionStyleDestructive
                                                     handler:^(UIAlertAction * action) {                                     
                                                          // ========
                                                          // Perform your delete operation here...
                                                          // ========
                                                      }];


// This cancel action will appear separated from the rest of the items
UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
                                                       style:UIAlertActionStyleCancel
                                                     handler:^(UIAlertAction * action) {}];


// Add the actions to the alert
[alert addAction:deleteAction];
[alert addAction:cancelAction];

// Present the sheet.
[self presentViewController:alert animated:YES completion:nil];

我通常忽略删除确认的标题和消息字段,因为我发现 iOS 上的内置应用程序(如联系人、消息、邮件等)通常不使用这些字段。按钮不言自明。

于 2015-08-17T19:19:07.263 回答
0

请参阅该 UI 组件的文档:UIActionSheetUIActionSheetDelegate

于 2012-05-28T16:19:45.163 回答