iOS 5.1 + UISplitViewController in PortraitMode + UIActionSheet in MasterController = Assertion failure - objective-c

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

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];
}

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.

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.

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.

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

Related

UIMenuController Editing Menu in UIWebView only appears second time

I am finding that in my app in iOS 9, when I long press in a UIWebView, the editing menu that normally appears, only appears the second (and following) times that I long press. The first time I long press in any particular webview no menu at all shows, although the selection handles do appear. The second time I long press in any partiular webview, it behaves as expected.
Another strange symptom is that occasionally (but not every time) as the menu appears, something quickly animates sliding of towards the left of the screen, originating from the menu, but it is too fast to see what it is. It happens even when the edit menu appears as it should. I expect this is related to the issue.
I have only tested in the simulator because I haven't installed iOS 9 on a device yet.
In iOS 8 the same menu works as expected.
Another developer gave me a work around, which may work when you have only one UIWebVeiw on screen. Put this in viewDidAppear (thanks Chen Xian'an):
[[myWebView.scrollView.subviews firstObject] becomeFirstResponder];
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self becomeFirstResponder];
}];
However, since I have more than one webView it is not an ideal solution for me. And if I apply it to each webview it only works on the last one I apply it to.
This appears to be a bug, and hopefully Apple will fix it soon, in the meantime, does anyone have any bright ideas as to how I could make this work for more than one webView?
I tried in this way, and I succeeded.
First
You must custom UIWebView and write
- (BOOL)canBecomeFirstResponder {
return YES;
}
Second
You must call this methods before handle your long press
[yourWebView becomeFirstResponder];
I hope it would help..
In my case the problem that was the UIWindow where the UIWebView was apparently not the key window. What i did to solve it was to add a call to [webView.window makeKeyAndVisible] at the webViewDidFinishLoad method.
- (void)webViewDidFinishLoad:(UIWebView *)webView {
// Fix
[webView.window makeKeyAndVisible];
}

UIAlertView in iOS8 appearing off-center, mis-placed, only portion of the screen dimmed

I'm building an iPad app on iOS8, landscape, upgrading from iOS7. I've replaced UIAlertView (deprecated) with UIAlertController in a number of other places in my app which has fixed this issue. However, I also use a UIWebView which apparently shows its own UIAlertViews. When this happens I also get the same problem (see partial pic, cropped). The alert view is misplaced lower to the left and only the left 2/3 of the screen is dimmed, and worse, the right most portion that is not dimmed still responds to touch gestures, so it's possible to control the app behind the modal!
The alert that the UIWebView throws is a standard "wants to use your location" alert. How do I fix this for UIWebView? Thanks!
EDIT: problem typically occurs when the app is brought to active state after trying to show the alert while backgrounded
I met a similar issue with iPhone, this happens when the application supports multiple rotation mask and is forced to strictly one. Basically, the viewController for example has shouldAutoRotate = NO, this only affects the view controller not the current window which is the alertView presented by the UIWebView.
Try implementing application:supportedInterfaceOrientationsForWindow
Here is an example:
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return (enablesRotation == YES) ? UIInterfaceOrientationMaskAllButUpsideDown : UIInterfaceOrientationMaskLandscape;
}
This tells that the current window must follow the desired supported orientation mask. Hopes this helps.

UIBarButtonItem sent action works on iOS 6 but not iOS 5

I am going to tear my hair out because I cannot think of a logical reason why this occurs on 5 but not 6. So basically, I have a view presented in modal fashion with a navigation bar and a Cancel button (UIBarButtonItem - no custom anything on it, just a standard button) in the navigation bar. When this Cancel button is tapped, I want the modal view to disappear. This works just fine in iOS 6. But for iOS 5 it refuses to work for 2 out of 3 places I have it in my code. What's odd to me is that it works on one but not the other two.
Using storyboards, I right click the button, click on "selector" under Sent Actions, and drag over to the appropriate IBAction method in my view controller's .h file. The link is successfully confirmed with the little blinking animation in Xcode. When I run the app on iOS 6 (simulator or device doesn't matter), the method is successfully executed upon button tap and my modal view dismissed. However, on iOS 5, the method is never even called (I set breakpoints inside the method to see if they would be hit). I've even tried switching the argument in my IBAction method from id to UIBarButtonItem *. No cigar, though.
I've also tried programmatically (in viewDidLoad) setting the cancel button's action to a selector. I've even set the target to the VC. No cigar again. Here is a screenshots of my current setup:
Please note the IBAction methods.
Is there some magical clause in the documentation that I missed? Something awfully special I need to do in order to get it to work in iOS 5? It sure seems like a bug to me, but I'm still fairly new to this stuff so what do I know.
I am using Xcode 4.5.2 and storyboards, and targeting iOS 5 and iOS 6 for the release.
Your help is appreciated, thank you.
I think there may be problem of using GestureRecognizer please comment that code and try it...
I added a separate UIView that resides under my textfields and button and below the navigation bar/title. I added the tap gesture to that programmatically, and that seems to recognize both my tap and the cancel button's action. I still would like to know why the tap gesture swallows up the UIBarButtonItem's action if the gesture is on the root view. This question helped me figure this out. Thanks.
you can exclude view/control from gesture recognizer using following delegate method.
// UIGestureRecognizerDelegate
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
// exclude your view from gesture recognizer
if(yourView == touch.view)
{
return NO;
}
//
return YES;
}

changing view controller when the device orientation changes

Im making an ios app in xcode 4 and I need a way of changing what is displayed on the screen when the device orientation changes.
does anyone know how to do this?
thanks.
probably you need to check first how to detect if the device orientation changes
see here: how to detect orientation change
then on the example on the link, you should know ho to change the view which is displayed on the screen. You can do it by using methods such as addSubview, presentModalViewController, pushViewController(for NavigationController)
eg:
[self presentModalViewController:aView animated:YES];
[self addSubview:aView];
[self.navigationController pushViewController:aView animated:YES];

iOS Developement: App Crashes on Reopen

My app is almost finish but when i am testing it, on first use everything is working well and smooth. But, after closing it from the home button and reopen it when i click my back it;s crashing.
in my back button i only have this code:
[view1 removeFromSuperview];
[view2 removeFromSuperview];
[self view3];
what could be the problem??
Why are you removing views from superview when you push the back button.
also what do you think will happen by saying
[self view3]; ?
I would suggest if you've added views in the viewDidLoad method
that you should remove them using the viewdidUnload method and not in the back button method. As if you try an remove a view that has already been release, your app will crash.
If you're attempting something different then you need to show more code.