How to do delete confirmation on iPad according to

2019-07-03 00:46发布

Reading through the iOS Human Interface Guidelines, it appears that there is no "right" way to have the user confirm before deleting. The Guidelines list 3 things when dealing with UIAlertView and UIActionSheet:

  • Do not use an alert view to confirm a user-initiated action.
  • Do not include a "cancel" button on an action sheet (on the iPad).
  • An action sheet must have at least 2 buttons.

So... I need to have the user confirm that they want to delete something. The only choices to present them with is to actually delete the thing, or do nothing (cancel). They can choose to do nothing by clicking outside the actions sheet, which dismisses it. But this only leaves 1 button for the action sheet. How are you supposed to do a delete confirmation?

On the iPhone, there is the modal / animated version of the action sheet which works great for this purpose. But the iPad completely changes the way action sheets are presented. The documentation says that you can still present an action sheet on the iPad as modal by presenting it with animation; but I have found that it looks and acts exactly the same whether animated is YES or NO.

2条回答
Explosion°爆炸
2楼-- · 2019-07-03 01:32

Tapping off of the UIActionSheet is the same as canceling it. And since the UIActionSheet is only a smallish window over top of (and usually pointing at) the option that called it, it doesn't own the user's attention. So the assumed intuitive action in that case is taping off of the UIActionSheet to make it go away. So that equals a cancel button (and why you "sometimes" don't need another one, according to the vague documentation).

From the UIActionSheet documentation page:

When presenting an action sheet on an iPad, there are times when you should not include a cancel button. If you are presenting just the action sheet, the system displays the action sheet inside a popover without using an animation. Because taps outside the popover dismiss the action sheet without selecting an item, this results in a default way to cancel the sheet. Including a cancel button would therefore only cause confusion. However, if you have an existing popover and are displaying an action sheet on top of other content using an animation, a cancel button is still appropriate. For more information see iOS Human Interface Guidelines.

If you implement the actionSheet:clickedButtonAtIndex: method, tapping off of the UIActionSheet will return a button index of −1. Other buttons start at an index of 0.

I think the takeaway is that the Apple guidelines are inconsistent or impossible in some scenarios. But it seems from the language of the documentation and my reading of the HIG that you should try to satisfy the conditions that make sense and not sweat it too much if it doesn't make sense in your implementation.

查看更多
淡お忘
3楼-- · 2019-07-03 01:39

I have a "Cancel downloads" UIActionSheet in my apps that I pop up to confirm, well, canceling downloads. I show it like this:

UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:nil 
                                                    delegate:self 
                                           cancelButtonTitle:nil 
                                      destructiveButtonTitle:@"Cancel downloads" 
                                           otherButtonTitles:nil];
[action showFromRect:self.cancel.frame inView:self animated:NO];
[action release];

where self.cancel is a UIButton in a UIToolbar. This gives the same effect as the "Delete" confirmation in the Photos app. If Apple does it for their software, I figure it's all right with mine...

Hope this helps!

查看更多
登录 后发表回答