Uiactionsheet Cancel Button Strange Behaviour

UIActionSheet cancel button strange behaviour

Instead of passing the current view controller's view to the action sheet, use the showFromTabBar: method of UIActionSheet.

The Right Way
This will give the correct tappable area:

[actionSheet showFromTabBar:self.tabBarController.tabBar];

The Wrong Way
This will put the tappable area in the wrong place (if you're using a tab bar or toolbar):

[actionSheet showInView:self.view];

If you're using a toolbar, use the showFromToolbar: method instead. You'll need a reference to the toolbar, most likely an ivar

[actionSheet showFromToolbar:self.myToolbar];

My Old Answer Also works, but is hacky:

Just found a possible answer:

01-Dec-2008 10:22 PM Tom Saxton:
I looked at this bug some more, and it seems to be an issue with the tabbar.

If you call UIActionSheet's [sheet showInView:self.view] from a view controller that is a child of a UITabViewController, then the hit testing on the cancel button fails in that portion of the UIActionSheet that lies above the tabbar's view.

If you instead pass in the UITabBarController's view, then the UIActionSheet acts as expected.

NOTE: in iPhone OS 2.1 and earlier, the UIActionSheet came up from the top of the tab bar when you pass the child view, but in 2.2, it comes up from the bottom of the tab bar, and thus covers the tab view.

http://openradar.appspot.com/6410780

Edit: It works correctly when I change the view to be the tab bar's view

[sheet showInView:self.parentViewController.tabBarController.view];

UIActionSheet in swift puts Cancel button top in iOS 7

Turns out this was yet another case of finding answer right after asking the question.

All I had to do was add Cancel button as another button and then specify its index:

var sheet = UIActionSheet(title: nil, delegate: self, cancelButtonTitle: nil, destructiveButtonTitle: nil)
sheet.addButtonWithTitle("Camera")
sheet.addButtonWithTitle("Photo Library")
sheet.addButtonWithTitle("Cancel")
sheet.cancelButtonIndex = 2
sheet.showInView(self.controller.view)

Not sure if they changed the way how UIActionSheet is supposed to work in Swift or if it's bug that nobody cares to fix since it's deprecated in iOS 8 anyway

ios UIActionSheet cancel button doesn't work right

My guess is that the bottom portion of the UIActionSheet extends beyond the bounds of the view, and so doesn't respond to touches.

To test this theory, add another button and see if all upper buttons work fine but the bottom button still exhibits this behavior.

To fix this problem, make sure the view extends to the bottom of the screen. If you have a tabBar in your app, that's going to be my suspect for the problem. You could use showFromTabBar: if you want the sheet above the tabBar, or showFromToolbar: to show it from a toolBar.

If you don't have a bottom bar, then I'm wrong and have no idea.

UIActionSheet cancel button not dismissing actionsheet

You need to display from a taskbar or a toolbar on iPhone as it clips some of the controls if you use display in view.

UIActionSheet, cancel button runs method

You need to implement something like this:

Change your if and else sections to add a unique tag for each UIActionSheet:

if(![giftTitle isEqualToString:@"bla"]) {
actionSheet = [[UIActionSheet alloc]initWithTitle:giftTitle
delegate:self
cancelButtonTitle:@"Back"
destructiveButtonTitle:nil
otherButtonTitles:@"Send via email", @"Read in Wikipedia" , nil];
actionSheet.tag = 10;
} else {
actionSheet = [[UIActionSheet alloc]initWithTitle:giftTitle
delegate:self
cancelButtonTitle:@"Back"
destructiveButtonTitle:nil
otherButtonTitles:@"Send via email", @"Read in Wikipedia", @"Pineapple mode", nil];

actionSheet.tag = 20;
}

Then look for the tag in the actionSheet:clickedButtonAtIndex: message handler:

case 2:
if (actionSheet.tag == 20)
[self showPineapple];
break;

This means [self showPineapple] will only run in the else scenario, while nothing will happen in the if scenario (just as nothing will happen for buttonIndex 3 in the else scenario (where the Cancel button is indeed at index 3) .

UIActionSheet on iPad is not showing cancel button

iPads have some special rules about action sheets and their cancel buttons, depending on where you are displaying it from:

You can present an action sheet from a toolbar, tab bar, button bar item, or from a view. This class takes the starting view and current platform into account when determining how to present the action sheet. For applications running on iPhone and iPod touch devices, the action sheet typically slides up from the bottom of the window that owns the view. For applications running on iPad devices, the action sheet is typically displayed in a popover that is anchored to the starting view in an appropriate way. Taps outside of the popover automatically dismiss the action sheet, as do taps within any custom buttons. You can also dismiss it programmatically.

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 iPad Human Interface Guidelines.

Here's a link with more explanation: http://crazyviraj.blogspot.com/2010/05/showing-cancel-button-in.html



Related Topics



Leave a reply



Submit