I have a tab bar controller with 7 tabs. Whenever I tap the more tab and return to the home screen, the app will unexpectedly crash. I found that moving between the more tab and the home screen produces a selectedIndex of 9223372036854775807. I rely on an array to grab specific content for each tab bar and the app breaks because that selectedIndex is out of range. Any thoughts on why this selectedIndex is appearing?
Related
I am working on the iOS legacy codebase with some SwiftUI views built. Everything looks good when app gets launched, but the Tab Bar title will be missing when navigate to another screen (either ViewController or SwiftUI view). It happens when navigate at the first time, the tab bar title will keep missing even though pops back.
This is how the tab bar looks after launching at the first time.
This is how the tab bar looks after navigating the other screens.
One more issue that I am facing is the navigation bar will be duplicate when navigate to a ViewController from SwiftUI view. The top one will be the nav bar from SwiftUI with a back button, the duplicate one will be from ViewController below the first one without the back button. What I expect is either the one from SwiftUI view with nav bar title, or the one from ViewController with the back button.
The top one is from SwiftUI view
Does anyone have some ideas how to fix them? Thank you!
I am facing a strange issue with Tab bar controller. I have a tab bar controller in main.storyboard working fine. I have 5 different storyboard references for each item and I could see all 5 tabs and tab bar is working fine in the simulator.
On selecting the 3rd tab, there is a button in 1st view controller that pushes to second view controller, here I am hiding the tab bar in viewWillAppear. Then when I push to 3rd view controller, I am showing the tab bar again in viewWillAppear.
Now when I select some other tab item from 3rd view controller and come back to 3rd tab, tab bar is not visible even though i have written below code:
override func viewWillAppear(_ animated: Bool) {
tabBarController?.tabBar.isHidden = false
}
Finally figured out the issue. One of my view controller in storyboard had hide tab bar on push view controller enabled causing the tab bar to hide in my expected view controller. On unchecking it and handling all hide/show tab bar in source code itself, i am able to fix the issue.
I have an app with a UITabBarController and a few tabs, each of which contains a UINavigationController. I also have a UISearchController triggered by a search button on the nav bar, which has a custom search results view controller. Search works just fine, as does tapping cancel. I implemented presentSearchController: to present the search controller as a view controller using
[self presentViewController:animated:completion:];
, which also works fine.
Where I run into trouble is if the user dismisses the keyboard (search controller active), and then switches tabs on the tab bar, comes back to the original tab with search controller active, and then taps "Cancel", the underlying UINavigationController's view stack is gone from the main window hierarchy and doesn't get reloaded until I switch tabs and come back with search mode inactive.
This is similar to this issue: "From View Controller" disappears using UIViewControllerContextTransitioning
Except I don't use any custom transitions, and the tab bar still shows after tapping cancel. Printing the view stack shows the tab bar is the only subview of the window until I switch tabs again and everything displays as normal.
What is the best way to go about solving this? I really hate to brute force re-add the navigation controller's view to the window on didDismissSearchController: as suggested. Not only does this seem like a bad idea, but I also run into issues with the z-ordering of the tab bar and the navigation controller when explicitly re-adding the nav controller to the key window.
Adding my brute-force solution:
- (void)didDismissSearchController:(UISearchController*)searchController
{
if (![self.view isDescendantOfView:[UIApplication sharedApplication].keyWindow]) {
NSUInteger currIndex = self.tabBarController.selectedIndex;
NSUInteger tempIndex = self.tabBarController.selectedIndex == 0 ? 1 : 0;
[self.tabBarController setSelectedIndex:tempIndex];
[self.tabBarController setSelectedIndex:currIndex];
}
}
i am doing tabbar application having fourths.When i reached first view controller first tabitem is showing highlighted.And when i clicked the second tab second tabitem is highlighted .My problem is when i clicked the button in the second view other view appears for that also tabbaritem is highlighting.
So is there any solution for that not to highlighany tabbar item when such kind of buttons is clicked and for same thing of iussue happening in the navigation bar button also when i clicked
I am developing an iPad application.
My application is a UITabBar based application with 5 tabs.
Now my requirement is to show a view controller outside these 5 tabs.
Explanation:
For example I have 5 tabs, A, B, C, D, E.
A is selected by default.
Now I have to show a new view controller say, F. But when I show that view none of the tabbar item should be selected.
What I have tried:
I created a UINavigationController as 6th tab. Now its not visible at the bottom and it nearly produces the effect I needed but have following two problems.
Tab bar items are not center aligned (Due to one hidden tab at right)
User can tab that hidden tab
Update:
Actually I am following an already developed application and I am sure its possible.
Scenario is I have 5 tabs that user can access without login. On navigation bar I have login button. When user is logged in I have a menu button in my navigation bar. Now tapping menu will show a view that doesn't belongs any of the tabs below. And that's why I need implementation explained above.
Work around I used to achieve above effect.
When I need to push my new UIViewController for which I want to deselect all of the UITabBarItem of my tabBarController, first I do the following things
Set selected index of tabBarController to last tab.
Set deselected image in last UITabBarItem
Get navigation controller of last tab and pop it to RootViewController.
Now push my new controller
Hide back navigation button in my view controller.
Hence I am able to show a Viewcontroller keeping user experience as current view is not in any of the tabs.
Thanx.
Sounds like a job for a modal view controller, i.e. one that's displayed in response to some user interaction other than selecting it via the tab bar.