How to control the origin of the uiview under the uinavigationbar - uiviewcontroller

I found that when I push a uitableviewcontroller from a uiviewcontroller, the origin of the pushed uitableview is right under the navigation bar. But if I replace the uitableview with another uiviewcontroller, the origin of the pushed uiview is from the 0. Therefore, there is some overlap between the navigation bar and the uiview. Anyone knows about this and how to solve this?

I can't visualize what your problem it, but i try to answer like this :). Any controller that push another view that view must have a container view. Example..
Navigation controller -> Root View -> Push view B -> Push view C..then any view B or C or Root View all of them inherit the navigation bar. All the controller view should not be overlapped by the navigation bar.

Related

How to change "MENU" button behaviour to not terminate App

Just right at the start: I don't want to change the user experience from Apple's user experience guidelines, I actually want to bring it back to my App, so here's the problem:
The "MENU" button should go back one level in the navigation hierarchy and terminate the App if there is no level anymore.
My first navigation screen also has an initially hidden full screen view (e.g. a video player). From this first navigation screen the user can go to deeper levels. The "MENU" button has its correct standard behavior.
The deepest navigation level then shows the hidden full screen view. When the user presses "MENU", the navigation should go back to the last level, but instead it terminates the App.
How can I change the behavior of the "MENU" button just for this single view?
It is not difficult to implement this. Just make sure the initial Screen that is displayed to the User is not the root View.
I will put the stack here.
Root View contains two views namely,
VideoContainerView and
MainContainerView.
VideoContainerView will have a UIViewController, which has menuHandler button listener. This VC displays anotherView on top of RootView on button press.
MainContainerView will have UIViewController, which doesn't have any menuHandler. MainContainerView is displayed on top of the VideoContainerView.
STACK
MainContainerView (Top)
VideoContainerView
RootViewController
RootView -> VideoContainerView (A View containing VideoScreenController)
RootView -> MainContainerView (A View containing MainViewController)
RootView -> VideoContainerView -> VideoScreen (Initial Screen, make sure this is a View Controller displayed on top of that FirstView using ContainerView).
From the VideoScreenController, Menu button press will display the RootView's MainContainerView which was hidden till now on top of that VideoContainerView.
On Next Menu button press, the app will go to background, as the MainViewController doesn't handle any menu Button press.
Never listen to any MenuButton press on the RootView's topView.
One can easily control the preferred focus flow using,
override var preferredFocusEnvironments: [UIFocusEnvironment] {
if topView.isHidden {
return [VideoContainerView]
} else {
return [MainContainerView]
}
}
Like wise, have preferredFocusEnvironments in every ViewController to handle the initial preferred Focus, so that system is aware which is currently focused.
The above code, helps the system to know, which view should be focused on launch or on every focus change.
The thing that actually causes your app to exit is if the pressesEnded:withEvent: for the Menu button press makes it all the way up the responder chain to UIApplication. So if you prevent that from happening, the app won’t exit.
There are two ways to do that: either somebody in the responder chain needs to override that method and not call super, or somebody in the responder chain needs to have a gesture recognizer that recognizes that button press.
UINavigationController, for instance, uses the latter. It also disables the gesture if the navigation stack is at its root; that way, attempting to pop the last view controller actually exits the app.

popToViewController presenting a black view

I have an app that has many different views. The entry point to the app is the home page where I have 2 buttons (note that the home page is embedded in a navigation controller). Each button leads to a new stack of views, I tried embedding the first view of those stacks into a navigation controller, but when I push a button on the home page that leads to a new stack, the app crashes giving me a "Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing a navigation controller is not supported'" message. So I avoided embedding the stacks into a nav controller. The problem happens when I push the save button in the last view of the stack. In there I did the usual
self.navigationController?.popToViewController(firstViewController, animated: true)
This does not work and I get sent to the firstViewController, however the navigation bar buttons don't show up, the background is black and nothing shows. If I popToRootViewController however, it works. Cheers!
Alright well I feel stupid now, I realized that the segues between my buttons and view controllers were push segues. Now I embedded the first view controller of both stacks in a navigation controller, and changed my segues into modal segues. By doing that I was able to use popToRootViewController instead of popToView Controller... Now my save button leads back to the view controller I wanted to show, everything works fine.

XCode Remove Navigation Bar From Tabbed Application

I created an app with XCode (tabbed application) and by default it has 2 ViewController. Then I added few more ViewController on my story board.
but I notice that those first two ViewController are different than ViewController I added.
XCode default ViewController for tabbed application it seems has some kind navigation bar on top. but I don't see it on others.
How to remove this 'navigation bar' on those default ViewController? so it has same appearance like others? thanks.
To remove this 'navigation bar' go to the document outline in the storyboard. Select the default view and remove the 'Toolbar'.

UIViewController navigation - Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted

In my app I use navigation controller to traverse between various viewcontrollers. I have view controllers A,B,C,D and E. I use push and pop to go back and forth. The issue is when the app is launched, I am able to traverse through the view controllers without any issues.
Before every push and pop I NSLog the view controller stack and it is as good as expected. But when I come to the root view controller again and start the navigation again, I am getting "nested push animation can result in corrupted navigation bar"
Even before the error when I NSLog the stack, the stack has no issues and is as expected. Then I get the error "Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted."
What is surprising is I am not able to debug because I am clueless where the error is coming from as NSLog of viewcontroller stack is fine. Kindly help me.
This article help me - http://keighl.com/post/ios7-interactive-pop-gesture-custom-back-button/
I just override UINavigationController.

Is there a way to override popToRootViewControllerAnimated: invoked by a tap on a Tab Bar Item?

I'd like to override the animation of popToRootViewControllerAnimated: (currently: YES) when a user taps on the same tab bar item that is already selected.
When the tab bar item is first tapped, I check whether the user is signed-in in the viewWillAppear: method of the tab bar item root view controller and if not, immediately push the sign-in controller with animation disabled.
controller.navigationItem.hidesBackButton = YES;
[self.navigationController pushViewController:controller animated:NO];
[controller release];
When the user successfully signs-in, I pop back to the root controller, [animation is] no problem:
[self.navigationController popViewControllerAnimated:YES];
However, the default behavior when tapping the current tab bar item again appears to make the following calls:
-[UITabBarController _tabBarItemClicked:]
which calls
-[UINavigationController popToRootViewControllerAnimated:]
I can't tell if YES is passed into that last one, but assume so based on observation.
If the user doesn't sign-in but taps the tab bar item again, it looks like the same [sign-in] controller is getting pushed/popped with animation since the viewDidLoad of the root controller just pushes the sign-in controller again. I'd like the animation to be NO in this one case.
To add to my problems, there are other navigation stacks where the sign-in controller can be pushed and it is appropriate for taps on its tab bar item to pop to the root controller.
I have implemented UITabBarControllerDelegate protocol and tabBarController:shouldSelectViewController: in the sign-in controller to check if the tapped bar item root controller is the same and if that controller is the class of the controller I want to special case, but it seems inelegant. Not only that, but now the sign-in controller must know about the class of a controller that could push it onto the navigation stack. While I can keep using the protocol method, there must be a better way to do this.
Thanks for your input and ideas!
I think the best solution to this problem would be presenting a modal view controller when the tab bar button is selected, and then returning NO. From the delegate method.