I am trying to create a UIActionSheet inside a UIViewController as follows:
discardAS = [[UIActionSheet alloc] initWithTitle:"title" delegate:self cancelButtonTitle:"Cancel" destructiveButtonTitle:"Discard" otherButtonTitles:nil];
discardAS.actionSheetStyle = UIActionSheetStyleDefault;
[discardAS showInView:[self view]];
When I evoke it - the entire screen "dim" (as if the actionsheet is actually in the foreground) - but I see no actionsheet.) It appears to be showing "offscreen".
WHen I try this on iOS7, I can see a white box shooting upwards, quickly going offscreen - as if it the ActionSheet is being placed above the top of the screen. When I click on the window, the dimness goes away, and all is normal - like iOS7 does if you tap out of the actionsheet and it goes away.
Thus, I am concluding the ActionSheet is being presented ABOUT (and out of) the confines of the screen.
I am also seeing the following on the console
Presenting action sheet clipped by its superview. Some controls might not respond to touches. On iPhone try -[UIActionSheet showFromTabBar:] or -[UIActionSheet showFromToolbar:] instead of -[UIActionSheet showInView:].
Both of which I tried, with the same results. Displaying self.view.frame shows a rect about 0,0,300,200 - so It's not grotesquely oversized.
Any idea why, or how to fix/debug?
For posterity - the answer was I had an "Extra View Controller" in my heirarchy - as described here: iOS 6: What changed that made this View Controller Hierarchy break?
Related
I have an app originally developed for iPhone, with a MapViewController as the main screen, and a Help screen and Tutorial screen both called from within a UI ActionSheet. Works fine for the iPhone.
When run on an iPad, I can't get to the Help screen and get the following runtime error:
Warning: Attempt to present <HelpViewController: 0x177076c0> on <MapViewController: 0x177d7060> which is already presenting <UIAlertController: 0x17732620>
If I add the following line of code
[self dismissViewControllerAnimated:YES completion:nil];
then I do get to the Help screen, but with the following error:
Warning: Attempt to dismiss from view controller <MapViewController: 0x17d75660> while a presentation or dismiss is in progress!
When I exit the Help screen, the MapView does not come up, however selection a new baseMap brings it back to life.
So, the code runs fine on an iPhone. On the iPad I get an error that says
1) Don't open a new view with the UIAlertController active, or
2) Don't dismiss the view, because a dismiss is already in progress...
Sure seems like a timing problem to me, I've tried both a "sleep" statement and some code to provide a short delay, neither have helped.
Anyone have any ideas?
you have to set action sheet for iPad like below..
UIActionSheet *popup = [[UIActionSheet alloc] initWithTitle:#"Some Title" delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:nil,nil];
if(!IS_IPad){
[popup showInView:[UIApplication sharedApplication].keyWindow];
}else{
[popup showFromRect:CGRectMake((CGRectGetWidth(self.view.frame)-200)/2, self.imgLogo.frame.origin.y,200, 200) inView:self.view animated:YES];
}
Surly your action sheet working in both.
This warning comes when you are trying to present/dismiss a view with animation while another animation is still in progress. This might be because while making a selection from UIActionsheet it animates and fades away and at the same time another viewcontroller is appearing with animation. It might help if you dismiss the view controller after delay of 0.2 seconds
I've got an iPad application that runs in both landscape left/right using MMDrawerController with a UISplitViewController as it's center view controller. The left view controller is a UIViewController with a UITableView to navigate between different sections of the app. Without rotating the device everything works fine and there are no issues, although when I rotate the device and try to open the left drawer and select a new view to push I receive the "Unbalanced calls to begin/end appearance transitions for .." error. Due to this none of the viewWillAppear/viewDidAppear methods run causing issues.
Here's how I'm changing the left pane of the split view controller in the left drawer UITableView:
NewsLVC *newsLVC = [[NewsLVC alloc] init];
[[[AppController sharedAppController].splitController.viewControllers objectAtIndex:0] setViewControllers:#[newsLVC] animated:NO];
[self.mm_drawerController setCenterViewController:[AppController sharedAppController].splitController withCloseAnimation:YES completion:nil];
I'm at a loss for what could be causing this, the only action that happens on rotate is calling a layoutView method but this occurs even if I comment out the line that calls it.
After a day of debugging this same problem, I found that it's due to the MMDrawerController manually passing on the rotation, which is unnecessary (and wrong) in iOS8. See this pull request for how to patch MMDrawer:
https://github.com/mutualmobile/MMDrawerController/pull/288
I apologize if this has been asked but I can't seem to find it anywhere. I even recreated my issue in a demo project in case any of you want to see it first-hand, although I don't know where I should post it.
I have a xibless UINavigationController based app. Some of my child ViewControllers have a button on the right side at the top that then displays a UIActionSheet. My app is designed for iPhone and iPad, so when I get ready to display the UIActionSheet I do:
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:[NSString stringWithFormat:#"%# Menu", [self title]] delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Email", #"Print", nil];
[actionSheet setActionSheetStyle:UIActionSheetStyleDefault];
if ([actionSheet respondsToSelector:#selector(showFromBarButtonItem:animated:)])
[actionSheet showFromBarButtonItem:[[self navigationItem] rightBarButtonItem] animated:YES];
else [actionSheet showInView:[self view]];
[actionSheet release];
On iPad, I'm trying to show the UIActionSheet attached to the right bar button and on iPhone it should slide in from the bottom. All of this works beautifully.
Unfortunately, if you tap the button and show the menu on iPad, but then tap the back button on the top left side of the app, the menu doesn't dismiss. Instead UINavigationController dutifully pops back and the UIActionSheet is still there. If you try to tap something on the menu you of course get a crash. If the user would have tapped anything else on the screen instead of the Back button, the menu properly dismisses.
If you try this test on iPhone, everything works as expected. There is no issue.
My demo project has an AppDelegate and a ViewController and that's about it. The AppDelegate builds an NSDictionary of NSDictionaries just so I have a model I can recurse through to demonstrate the issue. The ViewController shows all of the keys of the dictionary and if the corresponding value is an NSDictionary, you can tap it to drill down.
This is an interesting problem. Here's what the UIActionSheet Class Reference has to say.
On iPad, this method presents the action sheet in a popover and adds
the toolbar that owns the button to the popover’s list of passthrough
views. Thus, taps in the toolbar result in the action methods of the
corresponding toolbar items being called. If you want the popover to
be dismissed when a different toolbar item is tapped, you must
implement that behavior in your action handler methods.
So when you display the action sheet, it's automatically creating a UIPopoverController and set the containing toolbar (or navigation bar) as the popover's passthrough views, allowing touch events to continue. I think the best bet is to create an instance variable for your action sheet and to force it to dismiss if it is visible in -viewWillDisappear:.
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
if (self.actionSheet.window) // If action sheet is on screen, window is non-nil
[self.actionSheet dismissWithClickedButtonIndex:self.actionSheet.cancelButtonIndex animated:animated];
}
Have you tried force-dismissing the ActionSheet on viewWillDisappear?
Try this:
// In MyViewController.m
- (void)viewWillDisappear:(BOOL)animated {
[actionSheet dismissWithClickedButtonIndex:nil animated:animated];
}
*The crash sounds like a possible EXC_BAD_ACCESS. You might be losing your pointer reference to 'actionSheet' when you change views due to your release. Might be good to hang on to a reference to actionSheet in your .h file and manage the timing of your release.
*Also see the docs for info about the dismiss message: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIActionSheet_Class/Reference/Reference.html
I have an UIViewController. Within it the user may launch an UIActionsheet or a popover. If the device rotates, the UIViewController is intentionally released. The problem is that the UIActionsheet / popover lives on and becomes a zombie to haunt me afterward. The user may click a button in the zombie and crash the application. I tried to call [actionsheet dismissWithClickedButtonIndex:0 animated:NO] in dealloc or shouldAutorotateToInterfaceOrientation. No effect. Appreciate any suggestions. Thanks.
I found the solution from this post: [dismiss actionsheet][1]
[1]: iPad crash with UIActionSheet displayed from child view controller. I made a mistake trying to recall the actionsheet by searching through the UIViewController view's subviews or calling the viewWithTag method. Strangely enough, it did return a non-nil object. But using this object to call dismissWithClickedButtonIndex does not work.
The autor of the post suggests using an UIActionSheet pointer and dismiss the actionsheet in viewWillDisapper works. For the above specific application, I found it worked better to dimiss the actionsheet in dealloc.
I have an iPad app that has an MKMapView embedded in a UINavigationController which is displayed in a UITabBar. I am displaying a popover controller over the map with
UIPopoverController *myPopoverController =
[[[UIPopoverController alloc] initWithContentViewController:myContentView]
autorelease];
[myPopoverController presentPopoverFromRect:myRect
inView:mapView
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
The popover displays fine. However, it does not have the nice animated effect: it just immediately appears onscreen. Similarly, when I dismiss it it just disappears without any animation.
Anybody have any idea how I can get the animation to work? Should I try displaying it from another view? Is there some property on something that I might have neglected to set?
Despite the animated:(BOOL) parameter, it appears popovers never animate when presented. I've tried a dozen first and third party apps.
The dismissal should animate however, provided you pass YES to dismissPopoverAnimated:(BOOL)
Assuming your popover animates outside the map view, I would try placing the map view into a container view whose frame is the same size as the map view's. From there, it's trivial to present the popover in the container view.
According to Apple's documentation, MKMapView isn't supposed to be subclassed, so like UIWebView, it strikes me as one of those views whose guts are better left untouched.