presentViewController with the tabbar - ios

I have a app which has a tabbar which is presented in most of the ViewControllers. The problem is its not showing in an viewController which i'm presenting by this code.
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:songsViewController];
[self presentViewController:navigationController animated:YES completion:nil]
I'm using the presentViewController instead of the pushViewcontroller, cause i want to customize the navigationBar in this view.
How can i present my standard tabbar which i've created using storyboard?

When you use presentViewController:animated:completion, you are presenting the view controller modally, meaning it is not being contained within any of your existing containers like a UITabBarController or anything like that. So if you want something to show up when you present a UIViewController modally, it must be contained within the view controller that you're modally presenting. So from the looks of it, you're simply presenting a UINavigationController with your songsViewController contained within it. If you want to keep your UITabBar showing, either you need to add one to the view you're presenting, or you need to change your code so that you're not presenting a view controller modally here. And to add a second UITabBar for the modal view that matches the UITabBar that you were already presenting, it will make your app work rather strangely, so I would suggest trying to change it so you're not having to present a modal view at all.

Related

How to access the topmost UINavigationController

I have displayed two NavigationControllers in my iOS app. I need to access the topmost NavigationController programmatically. I tried
[UIApplication sharedApplication].keyWindow.rootViewController
but it returns the bottom NavigationController. How could I access the UINavigationController which is on the top using Objective-C?
you can use PresentingViewController property of the bottom navigation controller to reach to it's displaying controller, and then use the navigationController of the said controller.
something like this:
[[bottomNavController presentingViewController] navigationController]
but I strongly suggest that instead of this approach you walk up trough all your presenting controllers and find the last navigation controller that exists in the chain.
Cheers

Presenting a View controller only in the DetailViewController of UISplitViewController

I am working with UISplitViewController, and I want to present a VC from the detail view controller of the splitViewController. I do it like this:
[self presentModalViewController:VC animated:YES];
also tried this from master VC.
[self.detailVC presentModalViewController:VC animated:YES];
It comes for the full screen I mean it is like presenting from the UISplitViewController itself. I tried changing the modal presentation styles even though I got the same results.
What I want is the VC that is presented should be presented within the bounds of the DetailVC and it can be of DetailVC's entire frame, but not come anywhere near to the MasterVC.
For now I am using UIView Animation to achieve this, any ideas on how to do this just by presenting?
As of Xcode 6:
In the storyboard, select the present modally segue, and go to the Identity Inspector, and choose Current Context for the Presentation option.
Your detail view controller should be inside a navigation controller, then you push your additional view controller into the navigation controller instead of modally.

Does the navigation controls and other controls have to be within the appDelegate?

Is it possible to start your project with a single view controller, then on the second or third view controller implement the navigation controller, then maybe on the forth view controller implement the tab view controller? Or does this type of project need to be a storyboard project?
My dilema at the moment is that I start with just one single view controller that has a round rect button that takes you to the second view controller. From the second view controller, I would like a navigation controller with an embedded table view that will take me back and fourth from the second to the third view controller. I've been trying for hours putting the necessary code into each .h and .m file but I keep hitting brick walls.
Thanks in advance.
a. You can of course present several regular view controllers then add a UINavigationController at a later stage. When you need to present the navigation controller, you can embed your detail view controller inside one as follows:
(code is in the view controller which you want to display the detail view controller from)
DetailViewController *detailVC = [[DetailViewController alloc] init];
UINavigationController *detailNav = [[UINavigationController alloc] initWithRootViewController:detailVC];
[self presentViewController:detailNav animated:TRUE completion:nil];
b. It is not allowed to have a UITabBarController inside a UINavigationController (or any other view controller). You can however still use the UITabBar control and manage the rest. For an example of this, please refer to UITabBarController inside a UINavigationController.

dismissViewController is not working properly

Below is a hierarchy of my navigation controller
MainViewController
|
|
DetailViewController
Then I do the following on DetailViewController
[self presentViewController:reminderController animated:YES completion:nil];
After navigating to ReminderViewController, at some points I do
[self dismissViewControllerAnimated:YES completion:nil];
However, it brings me back to MainViewController instead of DetailViewController
That is weird. Any thoughts about this issue...
EDITED :
The reason I do presentViewController: reminderController animated: completion: on DetailViewController because reminderController is used to send a reminder. Just like goole app or other apps, when sending sth , we are using presentViewController.
Here is a sample of the documentation regarding the UIViewController class:
The presenting view controller is responsible for dismissing the view controller it presented. If you call this method on the presented view controller itself, it automatically forwards the message to the presenting view controller.
If you present several view controllers in succession, thus building a stack of presented view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. When this happens, only the top-most view is dismissed in an animated fashion; any intermediate view controllers are simply removed from the stack. The top-most view is dismissed using its modal transition style, which may differ from the styles used by other view controllers lower in the stack.
Thus, I think you should first use a segue to push your DetailViewController, and then present the reminderController modally, which you'll be later able to dismiss using dismissViewControllerAnimated:completion: without dismissing DetailViewController.
Instead of using dismissViewController:animated: use
[self.navigationController popViewControllerAnimated:YES];
dismissViewController:animated removes all the UIViewControllers in it.
You will save you a lot of trouble if you read the UIViewController and UINavigationController references. Twice ;)
See this post for more details.

pushViewController without navigationcontroller

I have a class that is of type UITableViewController.
This class has a member of type UINavigationBar that I use for adding in an edit button for the table view.
Using this method calling is invalid.
[self.navigationController pushViewController:controller];
How can I push a detail view onto the view after selecting a table row without wrapping my UITableViewController in a UINavigationController?
The closest alternative if you don't want to use navigation controller are modal view controllers.
[self presentViewController:controller animated:YES completion:nil];
This will slide the controller into your screen from bottom, or if you change controller's modalTransitionStyle it can flip over or fade in.
To dismiss the controller just call:
[self dismissViewControllerAnimated:YES completion:nil];
I would wrap the UITableView inside a UINavigationController and just hide the UINavigationBar.
[self.navigationController setNavigationBarHidden:YES animated:NO];
And then create a back button that pops the ViewController off the stack.
[self.navigationController popViewControllerAnimated:YES]
What could also be done is to use a Navigation Controller as usual and then hide it.
To hide the Navigation Controller using storyboards: select it and uncheck "Show Navigation Bar" in the attribute inspector. Others might suggest to hide the navigation bar in each controller, but the problem with that is that it will appear for a millisecond and then disappear.
You can't push a view controller onto a navigation controller if there is no navigation controller. If you are wanting to be pushing controllers and have it display the topmost controller and everything, just use a UINavigationController and be done with it.
You can push arbitrary UINavigationItems onto your UINavigationBar, and your bar's delegate will be notified when the user uses the back button so you can take appropriate action. See the documentation for more information.
It's true that without a UINavigationController you can not push view controllers. You rather present view controllers modally via UIViewController.present(_ viewControllerToPresent:, animated:, completion:)
But it's possible to create a custom segue to display the view controller as if it were a push (or any other animation you want), although it seems that using a UINavigationController just makes things easier.
Here are some related links to the documentation:
UINavigationController Class Reference
Customizing the Transition Animations
Presenting a Modal View Controller

Resources