Xcode IOS transition views with a tab view controller - ios

I am developing an IOS app using Swift and have a tab view controller. I start the app at the SecondViewController to allow the user to insert their information, upon clicking save I would like to programmatically transition to a different view. When I use the following code, the view transitions however the tab bar disappears.
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let home = storyBoard.instantiateViewControllerWithIdentifier("home") as FirstViewController
self.presentViewController(home, animated:true, completion:nil)
Should I not be presenting the view and just using a different form like segue or something?
Again this is a tab bar controller.
Thanks

Using presentViewController method, your particular view controller get's displayed modally above your current tab bar and navigation stack.
To keep your tab bar visible you either have to push your new view controller on the current navigation stack by calling the method pushViewController(..) on your current navigation controller, or - this is actually the right thing in your particular situatuin, assuming that you defined you FirstViewController in your storyboard and connected it to the first tab in your UITabBarController— you can simply tell your tabBarController to select the particular segmentedIndex (in this case 0).
Something like this should help:
self.tabBarController.selectedIndex = 0

Related

Back button disappears on show segue

I've read several posts about this issue, but I've been troubleshooting and the previous solutions don't seem to do the trick (i.e. the solutions specify embedding only the parent controller in the navigation controller, which I've tried). To address it as per previous posts, I've removed the embedding of the other views in their own navigation controllers -- but can't then seem to physically draw the segue from one table view to another; or it doesn't show the back button...
Basically, the "Back" button disappears on segue. It isn't seen in the second TableViewController and the last ViewController (on the end). It reappears in the parent, obviously.
EDIT: When I remove the navigation controller from the other two views, then no navigation bar appears on those VCs at all. The bar completely disappears, although it appears on the first one. This is how I have it configured now.
New Storyboard
Navigation Controller follows the Stack theory. When you push something in the stack it will increment the top index count by 1 and pop something in the stack it will decrease the top index count by 1.
In the navigation controller, first controller will be your root viewController. Now When you push new view controller in navigation controller, your top index count will be 2. But you are not pushing the viewController in same navigation controller (let say Stack1) you are creating the new Navigation controller (let say Stack2).
So here you are setting the new controller as the root viewController for new navigation controller(Stack2) and there are no item to pop yet that is why it's not showing the back button.
To Solve these Problem remove the navigation controller from the second and third view controller.
To push you can use segue or you can do it programmatically.
Swift
let vc2 = self.storyboard?.instantiateViewControllerWithIdentifier("ViewController2") as? ViewController2
self.navigationController?.pushViewController(vc2!, animated: true)
Objective C
ViewController2 *vc2 = [self.storyboard instantiateViewControllerWithIdentifier:#"ViewController2"];
[[self navigationController] pushViewController:vc2 animated:YES];
Navigation Controller Guideline
Edit
if you are not able to see the navigation bar on second VC
Make sure you are not hiding it by code in second VC.
Make sure you are pushing the second VC not presenting the VC.
Select VC in Interface Builder -> Attribute Inspector -> Top bar should be inferred.
if you are using segue then segue type(kind) should be Show.

swrevealviewcontroller navigation item and bar button missing

hello I have implemented SWRevealViewController in my swift app. The problem I am having is If I set SWRevealViewController as my initial ViewController all works fine. But If I launch this controller through code
let nav : UINavigationController = UINavigationController(rootViewController: self.storyboard!.instantiateViewControllerWithIdentifier("swrevealviewcontroller") as UIViewController)
self.navigationController?.presentViewController(nav, animated: true, completion: nil)
the navigation Title and barButtonIcon Disappears which is in my case is a hamburger menu icon.
SWRevealViewController is connected to the HomeViewController. and I am initiating SWRevealViewController when user clicks the login Button.
If you need more information regarding the storyboard screenshot let me know. I'll upload here.
Updated:
storyboard
navigation controller's navigation bar will only show up for view controllers that are contained by that navigation controller. Here, you're presenting a modal view. It's not contained by the navigation controller.
If you want the navigation bar to continue to appear:
If it's purely a matter of style, put a navigation bar on the modal scene you're presenting in the interface builder.
If you need to modally present a view that should be contained in a navigation controller, then you need to present a navigation controller--not a view controller.
Finally, if the view you're presenting is intended to be part of the navigation controller's navigation stack, then you need to present it with a push, not a modal segue.
Update
Do like simple ,
and call the perform segue as
[self performSegueWithIdentifier:#"main" sender:self];
I solved my problem by pointing Navigation Controller first and Tab Bar Controller second. Please, see the picture below.
Hope this help!..Thanks...

Navigation Controller Header is not showing

So, here I basically have this layout
but when I build successfully I am not able to see the title of the navigation controller.
What can I do?
This is what you want to emulate:
Set the UITabBarController as is Initial View Controller
add a relationship to each scene, whether it is a UINavigationController or not
If a scene is a UINavigationController, it will behave like any root navigation controller, with its own view stack, back button, an so forth.
Running the app above, then tapping on Item 2 will present this navigation controller:
If you cannot make the UITabBarController the initial View Controller at launch, you can make it become root later on using this technique:
let newViewController = self.storyboard?.instantiateViewControllerWithIdentifier("id")
as? UIViewController
self.view.window?.rootViewController = newViewController
This will present the architecture above, albeit without animation (nor any way to navigate back). Perfect for onboarding or login screens.
Tested on Xcode 7+, iOS 9+
Make your TabBar Controller the initial view, And make sure to remove the navigation controller that's linked to it, Then it should work fine.

dismissview controller is not working inside splitView or tabBar controller

Description: I have a Spilt view controller which has the masterController to display all the menu items and the secondary controller(DetailViewController1) is to display few details. Now I have DetailViewController2 which displays some other information.
Flow: SplitViewController which has the MasterViewController(table view for menu) -> DetailViewController1 -> DetailViewController2
Problem: If I present the DetailViewController2 using show segue then it is fine. If I use show detail segue then the navigation bar back button in the DetailViewController2 is not dismissing my DetailViewController2 to go back to the DetailViewController1.
Even if I use show segue it fails to dismiss. What I am doing wrong here?
You should use show only, Because Show detail segue replace the controller not push it
From Apple
Show Detail:
Present the content in the detail area. If the app is displaying a
master and detail view, the new content replaces the current detail.
If the app is only displaying the master or the detail, the content
replaces the top of the current view controller stack.
You can find more about it here
https://developer.apple.com/library/ios/recipes/xcode_help-IB_storyboard/Chapters/StoryboardSegue.html
Use two navigation controllers as the MasterViewController and DetailViewController of the UISplitViewController.
Embed your MasterViewController and DetailViewController1 in the nav controllers.
In DetailViewController1, when 'More Detail' button is clicked (or whatever triggers navigation to DetailViewController2):
{
let secondVC = self.storyboard?.instantiateViewController(withIdentifier: "DetailViewController2") as! DetailViewController2
self.navigationController?.pushViewController(DetailViewController2, animated: true)
}
This will present DetailViewController2 and the nav controller will handle navigating back to DetailViewController1 for free.
More info, including other benefits of using dual nav controller approach, here: http://nshipster.com/uisplitviewcontroller/

PerformSeque from button

Currently I'm writing a iOS app with Xamarin.iOS and I wrote a custom UITabbarController named BaseTabbarController. In this ViewController I made a centered raised UIButton over the TabBar to achieve something like this:
So this means that in my BaseTabbarController there is a onClick delegate for my button. When the button is pressed I would like to performSeque(push) to a new ViewController. The following code gives me the error: "Could not find a navigation controller for segue 'searchSegue'. Push segues can only be used when the source conroller is managed by an instance of UINavigationController".
So what should I do right now? I'm not sure how to fix this..
My storyboard looks like this and I'm talking about the second row.
If the button which causes push segue is on tabbar then you an not perform push segue on it because tabbar controller is supposed to be a rootview controller and to have push segue your controller must have navigation controller as container.
For example MyViewController is controller for view A and OneMoreViewController is controller for view B now you want to call view B from view A then embed view A inside navigation controller
// Programmatically
MyViewController *vc= [MyViewController alloc] init];
UINavigationController *nav = [UINavigationController alloc] initWithRootViewController: vc];
If you want to add that View A in tabbar then add nav object inside tabbar.
Now you can call viewB from view A using Push segue.
// and if your using storyboard then
Select the view which you want to embed inside navigationcontroller and choose Editor\Embed In\Navigation Controller from menu bar. that's it.
You've got a push segue hooked up from your tab bar controller to the navigation controller on the second row -- that's not right. That should be a relationship segue (i.e. one of the tab bar controller's view controllers, a second tab).
After Edit:
To be able to push that controller from any other controller on screen, all the base controllers in each tab will have to be a navigation controller. As long as that's true, you should be able to do this. The basic procedure would be to find out which navigation controller's stack is onscreen (with the tab bar controller's selectedViewController method), and perform a push in code from that navigation controller, using pushViewController:animated:. In the storyboard, you would want to have the controller you're pushing be disconnected from everything (no segues), and have an identifier, so you can get it from the storyboard to do the push.

Resources