4

After updating to iOS 5.1 from 5.0, an actionsheet presented from a button in the popover of a splitview controller is crashing the app. The error that its outputting is: * Assertion failure in -[UIActionSheet presentSheetInPopoverView:], /SourceCache/UIKit/UIKit-1914.84/UIActionSheet.m:1816 So in the Master View of the Splitview controller, I have a camera button that I attempt to present an actionsheet from asking to pick from camera roll or from camera. Any ideas?

if(lpm != null)  //Long Press Menu / Action Sheet
    lpm = null;
lpm = new UIActionSheet("Select an action to perform on " + Application.MO.CurrentList[indexPath.Row].Name);
foreach(var button in buttonList)
    lpm.AddButton(button);
lpm.CancelButtonIndex = buttonList.Count - 1;
lpm.Style = UIActionSheetStyle.BlackTranslucent;                
lpm.ShowFrom(theList.RectForRowAtIndexPath(indexPath), this.View, true);
lpm.Clicked += delegate(object sender, UIButtonEventArgs e2) {
                    lpm.DismissWithClickedButtonIndex(e2.ButtonIndex, false);
                            Application.MO.RespondToLongPressSelection(e2.ButtonIndex);
                        };
TChadwick
  • 868
  • 10
  • 19
  • Is it crashing the app immediately or when one of the options (camera/gallery) is selected ? – A-Live Mar 14 '12 at 23:51
  • It crashes the app immediately on the "ShowFrom" And it only affects iOS 5.1 users that just installed a fresh copy of the app, if they had it installed before they update to 5.1, it doesn't affect them and things work per usual. All previous versions of iOS seem to be unaffected. – TChadwick Mar 15 '12 at 14:23
  • Also Identified that it only happens on an actual iPad, if you try it in the simulator, it works fine. I believe this is due to the 5.1 simulator not simulating the new "Slide-in" transition for the Masterview when you touch the Navigation button. – TChadwick Mar 15 '12 at 15:01
  • I'm having the exact same issue now. I only noticed it after I uninstalled and installed my app. Still trying to figure out a solution. Perhaps presenting it from a different location. – Tap Forms Mar 19 '12 at 06:25
  • @Tap Forms, I am currently working with Xamarin to identify the issue, currently noted as bug #3913, I did find out a work-around however, which was to create my own popover, add my own view controller, and set the popover-content size after displaying them. (Incidentally it makes for a cool sliding-in effect) – TChadwick Mar 19 '12 at 15:18
  • They have reported the issue to apple. – TChadwick Apr 06 '12 at 16:37

2 Answers2

3

I ran into the same issue and have fixed it by showing it from the main window. Trying to show it from any other view or rect that is near the touched button causes the same crash. Following is the code to show in the middle of the screen only in portrait mode:

    if (UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation))
        [sortSheet showInView:self.view.window];
    else
        [sortSheet showFromBarButtonItem:sender animated:YES]; // rightBarButton

There are already several radar bugs reported. But please file a new one, so that they know it's happening to everybody.

Should you not be in a view controller use: [UIApplication sharedApplication].keyWindow to get the main window to show the view.

Conor
  • 1,781
  • 17
  • 27
  • Thanks, and we have submitted a radar bug. – TChadwick Apr 06 '12 at 16:36
  • Thank you. All the bugs filed for 5.1 have been confirmed as having several duplicates, so we should certainly expect a fix by 5.1.1 by then will all be using the if-else fix. – Conor Apr 07 '12 at 08:36
1

This is a potential work-around, it has me creating an entirely seperate popover and inserting my UIActionSheet into that, which conveniently adds a really cool slide-in effect:

var buttonList = Application.MO.LoadLongPressOptions(false);
if(lpm != null)
lpm = null;
if(longpresspopover != null)
{
    longpresspopover.Dismiss(false);
    longpresspopover = null;
}
longpresspopovercontroller = new UIViewController();
                    longpresspopovercontroller.View.BackgroundColor = UIColor.Black;
longpresspopover = new UIPopoverController(longpresspopovercontroller);
                    longpresspopover.PresentFromRect(theList.Frame, this.View,UIPopoverArrowDirection.Any, true);
                    lpm = new UIActionSheet("Select an action to perform:");
                    foreach(var button in buttonList)
                        lpm.AddButton(button);
                    lpm.CancelButtonIndex = buttonList.Count - 1;
                    lpm.Style = UIActionSheetStyle.BlackTranslucent;
                    lpm.ShowInView(longpresspopovercontroller.View);
                    longpresspopover.SetPopoverContentSize(lpm.Frame.Size, false);
                    lpm.Clicked += delegate(object sender, UIButtonEventArgs e2) {
                            lpm.DismissWithClickedButtonIndex(e2.ButtonIndex, false);
                            longpresspopover.Dismiss(true);
                            Application.MO.RespondToLongPressSelection(e2.ButtonIndex);
                        };
TChadwick
  • 868
  • 10
  • 19