iOS 5 issues: Navigation bar clipped after dismissing modal - iphone

I have a nice little app on the app store that does pretty well for itself. Life was great until iOS 5 came to town. Now, I have a number of issues with my app that I have no way of fixing because I have no clue what is going on, because I feel that they are iOS 5 issues, not mine.
Was there an iOS 5 conversion manual I missed? Or did they just change everything for fun, and want us to figure out where all the easter eggs were?
Here is another issue I am experiencing (that I have wasted so much time trying to fix), that DON'T EXIST AT ALL when I simply say that I want to run the app in good ol' 4.2:
Modal view
My app is a simple reader app. I have a book reading view that displays text with a UIWebView. One of the features I have been working on involves the ability to take notes as you read. This is achieved by hitting a button, and presenting a modal view. Yes, a modal view. The most simple pre- iOS 5 thing you could possibly do. Now, when I dismiss my modal view, just by hitting cancel, and simply dismiss the view, when I get back to my reader view, the navigation bar at the top is pushed up half way off the screen! This doesn't happen in 4.2, but there it is in iOS 5!
What can I do to get this issue resolved?
Thanks for your help.

Ok, I was just able to figure out what in the blazes was going on. I had the shouldAutorotateToInterfaceOrientation value set to a BOOL variable, so that when the modalView was coming back, it didn't know the state/size of the status bar. Fixed that, and the problem disappeared.

I have the feeling it has something to do with the way you present and dismissing the modalview. Apple introduced a new method to present views. May you try using theses instead of the old ones and see if it fixes your problem.
So here is what you do:
change this method:
presentModalViewController:animated:
into the new preferred method introduced with iOS 5:
presentViewController:animated:completion:
Depending if you are using dismissModalViewControllerAnimated:to dismiss your view, change it into dismissViewControllerAnimated:completion.
This methods also have completion handler which is very useful to do some extra work after the view has been presented/dismissed. Maybe that also helps with your other issue. Let me know if that might helped.

A major change in iOS 5 is that the navigationController property of UIViewController is no longer set for modal views. Instead, there is a new (not present in iOS 4) parentViewController property. So where you're using navigationController in a modal view you need to change the logic to something like:
UIViewController* parent;
if ([self respondsToSelector:#selector(parentViewController)]) {
parent = self.parentViewController;
}
else {
parent = self.navigationController;
}
(That's from memory, so I can't guarantee that every t is dotted and every i crossed.)

I was seeing this same clipping problem.
I found out that the reason for my issue was that I set the content size within the modal dialog (something I did for my iPad layout), so removing these two lines seemed to fix the issue:
CGSize size = CGSizeMake(320, 480);
self.contentSizeForViewInPopover = size;
I thought the problem was fixed but it wasn't. After reviewing the code some more, cleaning the build, and retesting it turned out to be a shouldAutorotateToInterfaceOrientation which would return NO for all orientations, for a brief amount of time (flag == NO) while the app is loading (root controller). You want to at least return YES to one orientation like so:
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return !self.flag ? UIInterfaceOrientationPortrait == toInterfaceOrientation : YES;
}

Related

iOS 5 UIWindow makeKeyAndVisible closes modal

I have a scenario where I present a modal view controller from the main window's rootViewController. While it is loading the contents of this modal, I am switching to another loading window which I make key and visible.
This window acts as a loading indicator and does not allow the user to interact with the app. When it is done loading, I switch back to the main window by making it key and visible. When I do this, the modal is force closed and the app is no longer able to present modals.
Interestingly enough, if I execute [UIWindow makeKeyWindow] when switching back to the main window, there are no issues. [UIWindow makeKeyAndVisible] is what's causing the issue. Is [UIWindow makeKeyWindow] an acceptable alternative?
This is iOS 5 only. No issues in iOS 6. I am not supporting iOS 4. Does anyone know what might be happening here?
I got the same behaviour, and as documentation states that makeKeyAndVisible method is a convenience method it seems to me legit to substitute makeKeyAndVisible call with working code:
[window makeKeyWindow];
window.hidden = NO;
Have no idea what's wrong, but it looks like a bug.
It is definetly bug in iOS 5 UIWindow implemetation. I faced this strange behaviour and Aleksey's answer is the way to go.

memory not releasing with ARC and storyboard in iOS 5.1

i'm cracking my head on memory issues with my app, the app are working fine except that it will crash once it hit low memory warning and are very very very laggy when using it for 10 to 20 minutes.
EDIT: how to poptoviewcontroller?
introvideo-> welcomeview & tutorialview-> mainviewcontroller-> scannerviewcontoller-> questionview ->(if answer correct -> correctView) else ->wrongView
how do i pop back to mainView controller ?
the below code are to solve adding view controller to the navigationcontroller.viewcontroller stack. As i'm using storyboard pushing from viewcontroller to another view contoller with out poping.
the code will pop to the viewcontroller that are already in the viewcontroller stack.
the flow of the of my storyboard as attached:
http://dl.dropbox.com/u/418769/storyboard%20flow.png
intro video -> welcome view & tutorial view (if username !exist) -> main view controller
this is the main file that user will alway go to.
http://dl.dropbox.com/u/418769/scannerViewController.h
http://dl.dropbox.com/u/418769/scannerViewController.m
i'm using a custom segue to pop viewcontrollers, which solved part of the problem.
-(void)perform {
UIViewController *sourceVC = (UIViewController *) self.sourceViewController;
NSInteger index = -1;
NSArray* arr = [[NSArray alloc] initWithArray:sourceVC.navigationController.viewControllers];
for(int i=0 ; i<[arr count] ; i++)
{
if([[arr objectAtIndex:i] isKindOfClass:NSClassFromString(#"mainViewController")])
{
index = i;
}
}
[UIView transitionWithView:sourceVC.navigationController.view duration:0.5
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
[sourceVC.navigationController popToViewController:[arr objectAtIndex:index] animated:NO];
}
completion:^(BOOL completed)
{
}
];
}
however, the app are still eating up the RAM and VRAM.
I really appreciate any friends here to help solving my question, does Strong value caused this problem ?
When you say that you're using a "custom segue to pop to the Main View Controller", I'm not sure if I quite understand that. Are you using performSegueWithIdentifier? If so, then you're not popping; you're pushing another copy of the main view controller!
In most storyboards, you don't see a segue out of the right side child view looping back to the left of the parent view (and your screen snapshot showed a dizzying number of segue's entering back into the main view controller, which is a bit of a red flag). This is a far more customary storyboard (taken from Beginning Storyboards in iOS 5) at Ray Wenderlich):
(source: cloudfront.net)
Usually you'll dismiss a child view with something like the follow, not use a segue.
[self.navigationController popViewControllerAnimated:YES];
Of, if you wanted to pop back multiple levels, you would use popToViewController or popToRootViewControllerAnimated. Or if you use modal segues, you would dismiss the modal with dismissViewControllerAnimated.
If I've misunderstood what you mean't by "custom segue to pop", can you provide what code you're using do to that?
Computer-aided analysis is the way to solve this. Do Build and Analyze and resolve all issues. Run your app under the Leaks and Allocations instruments. Use heap-shot analysis.
#ken-thomases analysis is spot on. Also see Finding leaks.
I presume you are using ARC?
Can you explain what is the purpose of the above code sample and what your app is doing to require something like this? It feels like you're addressing a symptom rather than solving a problem.
In answer to your question, the use of strong is unlikely to be the source of problems, unless you have strong reference cycles (see Transitioning to ARC). If you follow Ken's suggestions, you'll identify where your app is leaking memory (assuming it is), and if so, where it is. At that point, if you still don't understand the source of the leak, you can post the offending code here and I'm sure there will be plenty of people willing to help. Also, if you have some code that you wonder whether the strong reference is inappropriate, post that relevant code and, again, I'm sure we'll be happy to help if we can.

iOS - status bar randomly turns solid black

Developing an iPhone app.
I've got a really strange problem where, every once in a while, the status bar at the top of my app screen will turn solid black. Not like the black version of the status bar, but like a solid black rectangle with NO text/icons. It's very rare, but usually seems to occur after returning to the app via multi-tasking or from a locked device (the app has been running in the background). I've seen it occur on both 3GS and iPhone4. Here's a screenshot:
I can never reproduce it when trying, it just seems to eventually happen at some point (sometimes it will go for days without happening).
Once it does occur, the app seems to continue functioning fine, even with the status bar gone, except for when I do one specific action in the app which will cause everything to freeze up all the sudden (the app doesn't crash, but everything on screen is frozen and non-interactive). Without explaining the design in detail, the specific action that causes it to freeze up (after the bug appears) is performing a simple upload in the background to a SQL database. Resetting the app is the only way to fix the problem once the black status bar appears.
Anyone else ever experienced this? I can't find a single thread anywhere explaining similar behavior, and it's driving me nuts.
It happened once in my app when I called a drawing method in my custom subclass of UIView instance right before I added it as a subview to parent view.
The solution was apparently easy: add it as a subview first before sending/calling any custom drawing methods.
Examples:
CustomView *aView = [[CustomView alloc] init];
[aView drawSomething];
[self.view addSubview:aView]; //wrong approach
[aView release];
Should be:
CustomView *aView = [[CustomView alloc] init];
[self.view addSubview:aView];
[aView release];
[aView drawSomething];
The screenshot is missing, but what you describe sounds as though you've incorrectly implemented the use of Apple's built-in view controllers.
Both UINavigationController and UITabBarController will automagically shift all the content inside them down by 20-pixels, if they detect there is "supposed" to be a statusbar on screen at the moment.
My guess is that you have some code that is removing the statusbar, but which is kicking-in after the Apple code has already detected it and shifted everything down to accomodate.
The "fix" is to re-read the docs on Apple's classes very carefully and use them as Apple dictates (usually, people use them in ways that seem sensible - e.g. embedding them inside other views - but which Apple has expressly declared are unsupported. Sadly those classes from Apple are very fragile)
Are you holding a reference to a QLPreviewController instance? I was able to solve this problem in my app by creating a new autoreleased QLPreviewController whenever I need to display a file modally, as opposed to reusing the same instance over and over again.
I had a similar problem, which I described in this question here
If you have any, try removing any CGRect frame created by reference to:
[UIScreen mainScreen].applicationFrame]
and instead create the frame using a more manual definition. If that works, you can decide how to proceed from that point.

shouldAutorotateToInterfaceOrientation & UINavigationController

I'm trying to implement auto-rotation in my application that is basically UINavigationController with lots of UIViewControllers that get pushed onto it.
I've copy-pasted this in my first UIViewController (that gets pushed into UINavigationController):
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
Everything worked fine... However, if I paste in that code into second UIViewController (that first one pushes on top after some button click) - autorotation won't work. shouldAutorotateToInterfaceOrientation gets called when UIViewController is first initialized, but after it is visible and I rotate device - nothing happens.
So result is: first view gets rotated well - portrait/landscape... but after I click button and get into second view I remain stuck into that portrait or landscape, whatever was active.
I tried subclassing UINavigationController and setting shouldAutorotateToInterfaceOrientation there, but that also doesn't work.
What am I doing wrong?
There's a bug in the API that doesn't cause it to work for the second view. I solved it originally using setOrientation, but that's a private API and thus not a reasonable solution. I haven't released any new versions of the application while I try to figure out alternatives (and I don't think having customers upgrade to OS 4.0 is a solution). I'm thinking I'll need to manually keep track of the orientation and rotate my views manually to counteract the effects of the wrong rotation.
You need to implement this method in all views in the hierarchy

UITabBarController, UINavigationController and autorotate

i have problem with autorotate on iphone
i set up in all classes
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
but it is not respond ;/
Sample code is: http://b6.s3.p.quickshareit.com/files/testautorotatecb367.zip
problem is only with first tab, if i switch application to second tab, and rotate iphone, interface is rotating. it is not rotating in TAB1, where i put custom UINavigationController
OK
problem is that i do not init navigation views, i use only alloc, after i add alloc] init] all started works OK
Okay, i think i see what the problem is in you code. You need to add your UINavigationBar to the delegate like you did with the tab bar, otherwise it doesn't know of its existence and therefore it isn't rotating because it is confused on what is in the view.
Because I use Interface Builder to take care of all my GUI needs, i'm not sure how to do this manually in code, so, to help you out, here >> http://www.radford.edu/ebalci/Tutorials/SimpleTabNavTemplate.zip is a tutorial kind of thing i made a few days ago for a friend, you can use it as sort of a template or guide to help you out (i hope it will help you)
[my tutorial uses UItableViews for navigation but that is optional]
also, i commented out my rotation methods because i wasn't worried about it at the time, but
if you uncomment them (and i think you have to add the method to one of the classes because i deleted it) it will rotate, i just checked, but was too lazy to re zip it and upload it.
I just want you to know that I pretty much just made this thing a day ago, there is a rich text file in the zip that has instructions, but, it is a rough draft, i haven't really revised it yet so, i hope you can read through it with ease despite the fact it is a rough draft.
Let me know if it helps =) Good Luck
And your custom UINavigationController also has the same
shouldAutorotateToInterfaceOrientation
method that returns YES to landscape views?