iOS 5.1 + UISplitViewController in PortraitMode + UIActionSheet in MasterController = Assertion failure
Asked Answered
U

5

7

I have an app based on a UISplitViewController that shows an ActionSheet in the MasterViewController of the Split. Before iOS 5.1, I had no problems presenting the action sheet in the popover presented by the split, but now, apparently there is something wrong with the new "slide-in" way to show the MasterController.

The thing is that when I'm trying to present the ActionSheet, using any [actionSheet show..] method, the app crashes with the following error (The exact Assertion is the following).

*** Assertion failure in -[UIActionSheet presentSheetInPopoverView:], /SourceCache/UIKit_Sim/UIKit-1914.84/UIActionSheet.m:1816
sharedlibrary apply-load-rules all
Error in re-setting breakpoint 1:
Catchpoint 2 (throw)Error in re-setting breakpoint 1:
Error in re-setting breakpoint 1:
Current language:  auto; currently objective-c

I google this for a while, but no substantial answers.. some people say it can be a bug in the new SplitViewController...

Ideas?

Thank you in advance!

UPDATE: I posted a possible generic workaround, check it out. If it works for you, leave a comment.... If its ok, I will mark it as correct in a couple of days

Udall answered 15/3, 2012 at 20:47 Comment(10)
Well what's the actual assertion? Give us the message from the console.Gert
I edited the questions with the exact assertion.. thanksUdall
We need the next ten or so lines in the console after that.Gert
done!... but I don't think those lines are useful =DUdall
And now a backtrace please...Gert
Sorry Jonathan, I'm not sure what you mean with 'backtrace', but there is nothing in the console before those lines. In fact there is no additional code that may cause this crash. BTW, thanks man, I really appreciate your time.Udall
In GDB/LLDB, type bt to show a backtrace (which shows the series of function calls that led to the assertion failure.)Gert
I'm having the same issue too. Here is the backtrace I get: (gdb) bt #0 0x313d023c in objc_exception_throw () #1 0x35a57788 in +[NSException raise:format:arguments:] () #2 0x35a57788 in +[NSException raise:format:arguments:] () #3 0x3480c3a2 in -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] () #4 0x308a0492 in -[UIActionSheet(Private) presentSheetInPopoverView:] () #5 0x3068ed92 in -[UIActionSheet showInView:] () #6 0x00062d7a in ?? ()Corinecorinna
Same problem here. Have you found any solution? Thanks.Picador
FWIW, this seems to be fixed in iOS 5.1.1.Inexcusable
L
4

Based on the above, and with massive respect to the Apple engineer who helped me at WWDC, here is the solution which not only works around this bug, but also points the popover at the right button.

    if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]))
    {
        [actionSheet showFromBarButtonItem:self.actionSheetBarButtonItem animated:YES];
    } 
    else 
    {
        CGRect windowsRect = [self.navigationController.toolbar convertRect:self.actionSheetBarButtonItem.customView.frame toView:self.view.window];

        [actionSheet showFromRect:windowsRect inView:self.view.window animated:YES];
    }
Lathing answered 13/6, 2012 at 22:13 Comment(1)
If it's not a custom button, you have to calculate from navigationController.view size the location of the rect as there is no customView.Cymbre
C
2

I have this same problem too.

One workaround which prevents the crash at least is to show your UIActionSheet like this:

if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) {
    [self.actionSheet showFromBarButtonItem:sender animated:YES];
} else {
    [self.actionSheet showInView:self.view.window];
}

So in portrait mode, the action sheet is displayed in the center of the window. Not ideal, but at least it doesn't crash. And when in landscape mode, it behaves as normal.

Corinecorinna answered 19/3, 2012 at 6:59 Comment(1)
check my answer and comment your opinionUdall
O
1

Just as omz commented, it seems this issue has been solved in iOS 5.1.1 by apple. So I decide to just add it to known issue section of change log for my app, and the workaround is to suggest the users to upgrade to iOS 5.1.1.

Onieonion answered 2/6, 2012 at 6:53 Comment(0)
C
0

Another option to keep the popover affect of pointing at a particular option, you can actually do the following: 1. Create your own UIPopover 2. Create your own UIViewController inside of the UIPopover. 3. Display the UIActionSheet inside the newly created UIViewController. 4. SetPopoverContentSize from the UIActionSheet's Size. 5. Lastly, Wire your UIActionsheet's Clicked method to dismiss the popover.

Takes a little more code, but gives you the same functionality you had before for the most part, and has a cool little slide-in effect for the UIActionsheet.

Chestonchest answered 3/4, 2012 at 21:44 Comment(1)
check my answer and comment your opinionUdall
U
0

I think the following is a generic solution based on Tap Form's answer:

CGRect windowsRect = [actionSheetContainerView convertRect:viewToPresentActionSheet.frame toView:actionSheetContainer.window];
[actionSheet showFromRect:windowsRect inView:actionSheetContainer.window animated:YES];

This will resent the actionSheet in the window, but pointing the right direction

Udall answered 24/4, 2012 at 15:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.