UINavigationBar in Storyboards - ios

I just inherited a project that was made entirely in Storyboards. I have to fix some issues with spacing and poor management of art assets after segues and I'm having trouble getting at certain components.
My issue is this: The app is based off a UINavigationController hierarchy and the main screen does not require a UINavigationBar (and it screws with the spacing of the images when it first loads).
Project needs to be iOS 5.1 compliant (so no Autolayout or iOS 6 only features).
I need to hide the UINavigationBar when the app starts.
I can get it to "dismiss" after the app loads by doing this:
- (void)viewWillAppear:(BOOL)animated {
/* Hide UINavigationBar for iPhone until a segue is performed*/
[self.navigationController setToolbarHidden:YES animated:YES];
}
Even changing animated:NO gives the same result.
As a quick rundown, I have tried this in viewWillAppear, viewDidLoad and viewDidAppear.
Since it's dismissing after the view has loaded, I think calling to hide the NavigationBar in the appDelegate's didFinishLaunchingWithOptions method would do the trick, but because of the StoryBoard's I'm not sure how to get access to the Storyboard's Navigation Controller within the App Delegate.

I may be barking up the wrong tree here, but can't you just set it through the storyboards? Under "Simulated Metrics" you can define the TopBar for each single viewController, simply setting it to "None" for the main-screen's viewController.

How about just moving the nav bar off the screen instead?

I deleted the initial NavigationController the programmatically pushed to a UINavigationController after the initial ViewController in the Storyboard.
It was the longer way to do it (4+ hours ago) but ended up working for me.
Thanks for the input.

Related

Pushing viewController from viewWillAppear

I am trying to push a UIViewController (Called A) from viewWillAppear OR viewDidAppear of ViewController (Called B). Which is working fine.
But when I am popping A... B doesn't push it(A) again (Or I can say It is not showing its view) ... But when I am trying same after disable AutoLayout for my Storyboard, It is pushing A again after popping.
I have 3 solutions to resolve this issue... But I don't know why this is happening. Any one please update me about this issue. Thanks in advance.
When Auto Layout is enabled:
(ViewDidAppear)
rootViewController —————————————————————> demoViewController
(Push: animation:NO)
(Button Press)
demoViewController —————————————————————> rootViewController
(Pop: animation:NO)
As per code, rootViewController will push again demoViewController, But it is not showing demoViewController and navigationController is having demoViewController in its stack.
When Auto Layout is disabled:
Everything is working as we are assuming.
See the answer given in this question: Pushing view controller within viewDidAppear doesn't work
In my situation what you are describing was happening with auto layout disabled. This helped
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 250 * USEC_PER_SEC), dispatch_get_main_queue(), ^{
[self.navigationController pushViewController:[self.storyboard instantiateViewControllerWithIdentifier:#"myScreen"] animated:YES];
});
I don't know what view (and of what size) you have defined in the IB or in your code. Developers must have the through knowledge about using the AutoLayout feature in IB otherwise it leads to very nasty (unanticipated) bugs in the code.
So, i strongly recommend to go through this AutoLayout Guide: here I guess the contraints in views of viewcontroller A is giving the bug.
More precisely go to this page: Working with Constraints in Interface Builder
So, without trying couldbe or shouldbe be clear from this link.
You musn't push a view Controller into another in viewDidAppear or viewWillAppear. Because after you have to set variables when you want to come back...
Have you set constraints in your storyboard ? Because it can become from it.

Top half of UINavigationBar on iOS6 not responding to taps

I'm working on an iPhone app and have the strangest issue.
On iOS 6, buttons on the navigation bar are completely ignoring taps in the top half. Have a look at the image below, I have roughly selected tap areas of my navbar buttons:
https://www.dropbox.com/s/izs6ic5jlubm1yk/navtap_problem.png
Here's some, potentially useful, information:
the app supports iOS 6 and 7
the app is not using autolayout (working with deltas instead)
this issue is present only on iOS 6, it's working fine on iOS 7
the issue is present in all views across the app (that have a navigation bar on top)
the issue present in both navigation bars that are manually added in IB as well as in navigation bars that are coming from the UINavigationController
the problem is not present if I directly start the app from one of affected view controllers
the problem is present when I start the app through my empty InitialViewController and load another VC
I'm using ECSlidingViewController and loading the real VC (that users will see) from the InitialViewController like this:
self.topViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"SearchSplitViewNavigationController"];
[self resetTopView];
It looks like something invisible is covering the top half of the navigation screen. I checked the contents of self.view.subviews, but didn't see anything there.
Any ideas what might be causing this? Or what else could I check?
If you are including any element programmatically, then that element isn't using the deltas you are including through the storyboard.
For these elements you must test for the iOS version you're in and adjust the delta in code.
Check this: Best Way to check for iOS 7 or earlier? for help on the version checking.
I've found a solution (not the cause though). This awesome library helped me a lot to identify the problem.
There was actually a transparent UIView sitting on top of my navigation bars. It was located at 0,20 and had a height of 20 points.
That view is not in the self.view.subviews array, but doing [self.view bringSubviewToFront:myNavigationBar] seems to do the trick...

IOS7: Pop ViewController forces the UIImageView to drop

After upgrading my project to iOS7
when I do a BACK Button and the UINavigationController goes back to the previous page, an ImageView on the top of the screen shifts down.
I use IB to do my layouts. These are my Simulated Metrics:
I have AutoLayout off. Any ideas on what the issue might be? I wasnt sure if anyone wants to see specific code and I didnt want to clutter up the question with too much code.
Updates: Based on the comment questions, I wanted to make these updates:
In no place in the application .h or .m file do I make any changes to the imageview's sizes or location.
In both the viewDidLoad and viewDidAppear I call a user-defined method called recalculateAll but their is no reference at all to any imageview sizes. Just for trying it out I commented out the entire section and ran the code and it still jumps down.
In my init I do programatically set some imageviews (you see the #132 in what appears to be a bubble) using their x and y's.
Here is a typical navigation I use for moving from the view controller to the tableviewcontroller:
GetTimeOffByType *showTimeOffReport = [[GetTimeOffByType alloc] initWithNibName:#"GetTimeOffByType" bundle:nil];
showTimeOffReport.timeOffType = #"Vacation";
[self.navigationController pushViewController:showTimeOffReport animated:YES];
These are all .xib files, no storyboarding at all. Its basically a view controller which has an embedded UINavigationController with 6 buttons. Each time a button is pressed it pushes a UITableViewController passing different parameters and showing different data. The transition I am using to get back to the original UIViewController is simply the iOS generated BACK button (so no code to show for that)
Update#2 Hopefully this will help someone solve this wierd behavior. So if I were to click on the table view cell on showTimeOffReport to get the cell detail and then using BACK navigate all the way back it doesnt jump down.
Update#3 Ok this is something I just discovered : The issue of jumping down or not is related to the translucency of the UINavigationBar. If you have a Translucent = YES it will start from the top of the window. If you have a translucent = NO it will start from the bottom of the UINavigationBar.
You might try setting the new property on UIViewController edgesForExtendedLayout to UIRectEdgeNone.
Here is a good resource that explains more about how view layouts changed in iOS 7.
See Apple Documentation
If you plan to be backwards compatible you will probably need to do some runtime checks and adjust positioning if the device is not running iOS 7.
This might help you..You can try adding UIViewControllerBasedStatusBarAppearance key and set it's value NO in your info.plist
UIViewControllerBasedStatusBarAppearance = NO

presentViewController is disabling all removeFromSuperview messages in a UISplitViewController

Here is a visual representation of the UISplitViewController:
I'm trying to present a UIViewController (myVC) that's a subview of a UIView inside the DetailViewController of a UISplitViewController using this:
[appDelegate.splitViewController presentViewController:myVC animated:NO completion:nil];
It presents, I dismiss it, the app rotates without a hitch, then when I try to reload the detail view by clicking on a cell in the rootViewController (a UINavigationController), all the [orangeUIView removeFromSuperview] messages are mysteriously disabled (there are more orange UIViews hidden here that are inside a mainScrollView). The "INFO LABEL" in the topToolbar is updating, so I know the cell is sending data...
Why would this activity disable removeFromSuperview if presented using splitViewController? I've presented myVC using the detailViewController...
[appDelegate.detailViewController presentViewController:myVC animated:NO completion:nil];
which doesn't disable removeFromSuperview, but causes an assortment of other rotational crashes.
What's going on here?
Since this question was created as a result of a previous question, the answer to this problem was...try something else. I was unable to fix this problem by presenting a view controller, most likely because I'm using a custom UISplitViewController with a hierarchy I'd rather not get into.
Here is the solution I came up with:
Core Plot - Options on making the graph full screen - addSubview after presenting modal problems

Adding UIViewController.view to another view causes orientation problems

Short version:
I'm alloc/init/retaining a new UIViewController in one UIViewControllers viewDidLoad method, adding the new View to self.view. This usually works, but it seems to mess up orientation change handling of my iPad app.
Longer version:
I'm building a fairly complex iPad application, involving a lot of views and viewcontrollers. After running into some difficulties adjusting to the device orientation, I made a simple XCode project to figure out what the problem is.
Firstly, I have read the Apple Docs on this subject (a small document called "Why won't my UIViewController rotate with the device?"), and while I do believe it has something to do with one of the reasons listed there, I'm not really sure how to fix it.
In my test project I have an appDelegate, a rootViewController, and a UISplitViewController with two custom viewControllers. I use a button on the rootViewController to switch to the splitViewController, and from there I can use a button to switch back to the rootViewController. So far everything is great, i.e. all views adjust to the device orientation.
However, in the right viewController of the splitViewController, I use the viewDidLoad method to initialize some other viewControllers, and add their views to its own view:
self.newViewController = [[UIViewController new] autorelease];
[newViewController.view setBackgroundColor:[UIColor yellowColor]];
[self.view addSubview:newViewController.view];
This is where things go wrong. Somehow, after adding this view, adjusting to device orientation is messy. On startup everything is fine, after I switch to the splitViewController everything is still fine, but as soon as I switch back to the rootViewController it's all over. I have tried (almost) everything regarding retaining and releasing the viewcontroller, but nothing seems to fix it.
As you can see from the code above, I have declared the newViewController as a property, but the same happens if I don't.
Shouldn't I be adding a ViewController's view to my own view at all? That would really mess up my project, as I have a lot of viewControllers doing all sorts of things.
Any help on this would be greatly appreciated...
I had the same problem, seams resolved by removing from the parent view the "autoresize subview" option in IB.
Select the view a then: Inspector -> Attributes (first tab) -> drawing.
What I think is happening is that your new viewcontroller is getting the autorotation calls and probably not handling them. Meanwhile your old viewcontrollers and its views won't get the autorotation calls and will be stuck in whatever orientation they were in.
I can't tell, but I think what you want to do is to make a UIView and add it to your old viewcontroller, instead of making a UIVIewController and adding its view.

Resources