I got 2 subviews in a TabBar app. I should go to the 1st view from the 2nd, but not with help of tabbar, but throught another button, which is on the 2nd view.
If i create simple segue (between bytton on the 2nd view and the 1st view), tabbar will think, that i am still on the 2nd view and the 2nd button on the tabbar still highlighted.
Do you know correct way to realise it?
You can try to use the UITabBarController.selectedViewController property instead of segue.
If you want to change your view without touching tababr controller
use this line of code where you want to use
self.tabBarController.selectedViewController=[self.tabBarController.viewControllers objectAtIndex:1];
using this line you can move the 2 tab of the tabcontroller without touching tabbar.
Related
I am new in iOS development and in Swift. I have a question. I added in one of the ViewController NavigationController. But I have some problems with back button cause it doesn't appear on other Views. I tried with self.pushViewController() and with self.present() but it doesn't work. If I mark in NavigationController Is Initial View Controller then everything is fine but I don't want it because then app starts with this screen(where I have NavigationController).
Please help me, what I should to add or to write?
This is an image of my storyboard
And this is what I have if I run and go to another ViewController, as you can see I don't have navigation bar and back button.
You got 2 options :
1) Add a navigation controller in the root ViewController, Hide throughout except the last one. Make sure you push the last VC so Back option will be there by default
self.navigationController.pushToViewController(BarCodeViewController)
2) Use a custom View on top of last viewController add a custom button to that view. But this time present it from previous ViewController
self.present(BarCodeViewController)
when back button clicked dismiss it by adding target to the button. self.dismiss()
I have a UITabBarController with many UIViewControllers resulting with a "More" TabBarItem.
One of those views has some editing functions I'd like to place in the UINavigationBar and I can replace the right and left button items, no problem. However, there seems to be an issue when you move that view controller where the navigation controller is no longer displayed. I believe I can solve the issue if I know from where the view is loaded from.
Here is my challenge I need some direction on:
What is the best way to check to see if the selected view is not being presented with the top navigation bar? Meaning, there is no "< More" on the top. That way I can display my own Edit button.
Any view controller can ask for its tabBarController. From there, it can get the tab bar controller's moreNavigationController. So now it can ask whether its parent is the moreNavigationController.
Should be able to check if there is a left bar button item using
navigationItem.leftBarButtonItem == nil
or
navigationController?.navigationItem.leftBarButtonItem == nil
depending on your hierarchy.
I have added a show segue from table cell in one view controller to another table view embedded in a navigation controller. When I click on the cell in the first view the segue works as expected and brings up the new view. However, the "Back" button (with the title of the original view) does not appear in the navigation bar.
I searched SO and found a number of such questions asked in the past (both for Swift and Objective-C). Most of them suggest that the first view needs a title for this to work. I do have a title. I even added one programmatically, just in case. That did not help. One of the answers suggested to add an identifier to the segue; that didn't help me either.
How else can I debug this issue?
It seems like the problem is that you are pushing into a totally new navigationController, remove it, and make segue dirrectly into the new view Detail itself, they have to be in the same navigationController to work
Verify you are not hiding backbutton in destination controller...
I had a left bar button item in storyboard removing the button, back button showed up.
Alright, here is the deal.
I have a UINavigationController which has a root VC. From this root VC, you can show another VC, and from there, another, and from there, another.
The problem is that I'm running into what I think is a bug in Xcode.
In the below image, you see a button in my rootVC navigationItem that I use to segue with Show to display the second VC. You can clearly see the Navigation Bar, but when I try to drag a UIBarButtonItem into it, I can't and the reason is because if you look at the menu on the left, you'll see that there isn't a Navigation Item to drag the button into!
If I instead use the segue Push to display the second VC, I get a navigationItem... but apparently Push is deprecated.
How do I mitigate this?
Edit: I guess I can just drag in a UINavigationItem into it... but I really don't know if I should. Would there be an empty UINavigationItem underneath that that I just don't see in storyboard but is actually there?
The navigation item is not created automatically on the second view controller, you're right. Drag a new navigation item into the second viewcontroller's bar, and you should be good to go.
I have an iOS application with a Tab Bar, and two subview. My first view is a Table View.
So, I want to switch to the second view when I click on a cell of the first view, and keep the TabBar visible.
When I do that using "Show" segue in the storyboard, I lost the TabBar.
And when I do it in my TableViewController with the following code, the second view is not loading.
tabBarController.selectedViewController = mySecondViewController
That only select the second element in the TabBar, but didn't display him.
Anyone have a solution ?
try using index of UITabBar item to switch, like this:
tabBarController.selectedIndex = 1
The problem also may be because you try to set View to selectedViewController, where uiviewcontroller should be. It is hard to say, because of lack of information.
In the story board make sure you control drag from the tab bar controller to your view controller and click "Relationship Segue: View Controller"
I've fix my problem. I've originally put the line of code bellow on the viewDidLoad() of my controller :
tabBarController.selectedViewController = mySecondViewController
After moving this line in a different methode, call by a simple button, that worked...