Tab Bar mysteriously disappears? - swift

Attached are two images. The first shows my current main.storyboard, and the second shows my problem when I run the app. I have a tab bar controller that has two tabs. On the first tab there is a button. When pressed, the button goes to another view controller with content. At the top is a Navigation bar with a back button. After viewing content, I press the back button, and am back on the original page with the button, but the tab bar is missing. I have seen a few answered questions, but it appears they made their tab bar in the view controller instead of the storyboard. Another says that I should never return to a previous view unless I use an unwind segue. Is this true? If so, how do I set up an unwind segue. If not, how do I fix this problem otherwise? Thank you.
http://i.stack.imgur.com/IYmX2.png
http://i.stack.imgur.com/7slt5.png

The problem is in the wiring of your ViewControllers. You have probably embedded your UITabBarController inside the UINavigationController and not the other way around.
A correct layout looks like this in Interface Builder :
To reproduce:
In Interface Builder drop a UITabBarController. This will come with 2 UIViewController's already wired in.
Pick one of the UIViewController's (let's call it VController1) and click on Editor / Embed in / Navigation Controller. This wires the VController1 to live inside a UINavigationController that is inside the UITabBarController
Add a 3rd UIViewController next to VController1 Let's call it VController3
Wire in a segue between VController1 and VController3, for example with a button.
I hope that's clear enough

Try Linking the button in your viewcontroller (other than the views of the tabbed bar controller) with the tabbed bar controller. Create a segue that links the button with the controller of the tabbed bar application

Related

Is Initial View Controller does work?

I have a viewcontroller and a tab bar controller. I want to change view controller as initial view controller and create a segue to show tab bar controller.
I have tried to set the new initial view controller. There are 2 ways. First, check the tick box "Is Initial View Controller". Second, drag the arrow to new screen. It does not show any error, but it shows the tab bar controller as usual and I can't find the view controller either.
Anyone know how to what is going on. Please tell me to fix. Thanks
You need to use a UINavigationViewController and connect it up in the hierarchy in a similar fashion to:
The leftmost view is the "view" that you mention, which needs to show the UITabViewController.
I've added a button for ease of use.
The next along (send from the left) is the UINavigationViewController. No settings on here need to be set etc... it's pretty much "plug and play" as to put it.
The next view (third from the left) is the UITabViewController (with corresponding views to it's immediate right).
The connection between the UINavigationViewController and the UITabViewController is "rootViewController" as the Tab View is the "root view controller" e.g. the primary view controller.
The segue between the first view, and the navigation view controller is merely a "show" segue. I liked directly between the button and the navigation controller in Xcode.
Hope this mash-up helps!
Edit I wrote a quick mask up of what I posted in the images for you to play with: https://dl.dropboxusercontent.com/u/61211034/Stackoverflow/NavgationViewController.zip
Based on your storyboard's image, looks like you don't have any NavigationController embedded to your root LoginViewController, try this:
Select your LoginViewController on your storyboard
Then in xcode Menu bar at the top, go to Editor -> Embed in -> Navigation Controller (as you can see in the image below)
Then your NavigationController will be set as your Initial View Controller, and see your LoginViewController be displayed and work as expected your segue.

Navigation bar object in xcode 5 not showing back button and has no functionality

I have been trying to properly setup a navigation bar in one of my View Controllers for an hour now and have not found any working solutions.
I control-clicked on a button on my app's initial view controller(1st VC) and dragged to another view controller(2nd VC) and selected "modal" as the action segue.
I then added a navigation bar item to my 2nd view controller.
When I run my app on my iPhone, I can tap on the button on my app's initial screen and it will take me to my 2nd VC, and the 2nd VC does display the navigation bar, but the navigation bar does not have the default iOS 7 back arrow to let me go back to the app's initial VC.
I was under the impression that this could be setup exactly like I did above and that the back button functionality would be included by default.
Am I completely lost? Do I need to further customize navigation bar programmatically or with a tick box in the attributes inspector? Is "modal" the wrong action segue option?
I basically just want to have navigation bars at the top of a couple of my VC's so that the user can easily get back to the app's initial screen.
Thanks for the help.
Since you are presenting your second screen (2nd VC) as MODAL from your first screen (1st VC), you will not see the back arrow button on navigation bar. Your understanding about back button works for Navigation view controllers (push segue). For MODAL you need to put a cancel button on second VC's Nav bar and put a dismiss action for that.

Persistent UIBarButtonItem on all navigation bars within tabbarcontroller

Ok so I have a tabbar iPhone application. The tabbarcontroller contains about 5 view controllers that are each embedded in their own navigation controller with the exception of 1 in which I just added a navigation bar in IB for a consistent look throughout the app. On every navigation bar in the app, I want a rightBarButtonItem that will open up the same modal view controller no matter where it is selected from. Similar to the "Now Playing" button in the music app, I want the button to stay on every navigation bar regardless of which tab I'm on or how deep I navigate into a navigation controller. How would I go about doing something like this? Is there some way I could simply apply the button to every nav bar in the same way UIAppearance can apply an image to every nav bar in an app? Thanks in advance for any ideas.
A simple approach would be to create a base view controller from which all your other view controllers extend.
With this in place, you could set up a UIBarButtonItem in the viewDidLoad method that attaches itself to the navigation bar and listens for events. From there, it would be quite easy to observe events and present either a modal view controller or push the appropriate view controller on to the navigation stack.
I use this approach for a "logout" bar button item that presents the login view controller when tapped as a quick alternative for users to sign out of their account.
The only down side to this is that each and every view controller that inherits from the base view controller will have the logout button in the navigation bar. Should you need other buttons or want to hide the default button, you need to replace it with another button instead.
It's a quick and easy approach and is also quite simple to remove if required as you can just change the header file to reflect the inheritance rather than sifting through several view controllers removing every instance of the button. It's also easy to maintain as you could overload the button target in any subclasses to perform different functionality when the event is fired.

Problem in adding more than 5 button in tab bar controller in iphone

Hello everybody i need your help.
I am making a tab bar based application in iphone. i have more than 5 button to show in tab bar. when i did it, five button displayed fifth button is more..... but when i clicked on more then more button came in a table view not in tab bar.
That's how it works. From the documentation (http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/TabBarControllers/TabBarControllers.html%23//apple_ref/doc/uid/TP40007457-CH102-SW2):
If you add more than five items to the
viewControllers property, the tab bar
controller automatically inserts a
special view controller (called the
More view controller) to handle the
display of the additional items. The
More view controller provides a custom
interface that lists the additional
view controllers in a table, which can
expand to accommodate any number of
view controllers. The More view
controller cannot be customized or
selected and does not appear in any of
the view controller lists managed by
the tab bar controller. For the most
part, it appears automatically when it
is needed and is separate from your
custom content. You can get a
reference to it though by accessing
the moreNavigationController property
of UITabBarController.
That is intended behavior and not an issue, if you read the viewController Programming guide you could have seen that right away: http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html#//apple_ref/doc/uid/TP40007457

UINavigationBar unresponsive after canceling a UITableView search in nav controller in tab bar in a popover

Ok, this is an odd one and I can reproduce it with a new project easily.
Here is the setup:
I have a UISplitViewController. In the left side I have a UITabBarController. In this tab bar controller I have two UINavigationControllers. In the navigation controllers I have UITableViewControllers. These table views have search bars on them.
Ok, what happens with this setup is that if I'm in portrait mode and bring up this view in the popover and I start a search in one of the table views and cancel it, the navigation bar becomes unresponsive. That is, the "back" button as well as the right side button cannot be clicked.
If I do the exact same thing in landscape mode so we are not in a popover, this doesn't happen. The navigation bar stays responsive.
So, the problem only seems to happen inside a popover.
I've also noticed that if I do the search but click on an item in the search results which ends up loading something into the "detail view" of the split view and dismissing the popover, and then come back to the popover and then click the Cancel button for the search, the navigation bar is responsive.
My application is a universal app and uses the same tab bar controller in the iPhone interface and it works there without this issue.
As I mentioned above, I can easily reproduce this with a new project. Here are the steps if you want to try it out yourself:
start new project - split view
create new UITableViewController class (i named TableViewController)
uncomment out the viewDidLoad method as well as the rightBarButtonItem line in viewDidLoad (so we will have an Edit button in the navigation bar)
enter any values you want to return from numberOfSectioinsInTableView and numberOfRowsInSection methods
open MainWindow.xib and do the following:
please note that you will need to be viewing the xib in the middle "view mode" so you can expand the contents of the items
drag a Tab Bar Controller into the xib to replace the Navigation Controller item
drag a Navigation Controller into the xib as another item under the Tab Bar Controller
delete the other two view controllers that are under the Tab Bar Controller (so, now our tab bar has just the one navigation controller on it)
inside the navigation controller, drag in a Table View Controller and use it to replace the View Controller (Root View Controller)
change the class of the new Table View Controller to the class created above (TableViewController for me)
double-click on the Table View under the new Table View Controller to open it up (will be displayed in the tab bar inside the split view controller)
drag a "Search Bar and Search Display" onto the table view
save the xib
run the project in simulator
while in portrait mode, click on the Root List button to bring up popover
notice the Edit button is clickable
click in the Search box - we go into search mode
click the Cancel button to exit search mode
notice the Edit button no longer works
So, can anyone help me figure out why this is happening?
Thanks,
Mark
Ok, got an answer from Apple Developer Technical Support. They investigated it and found it is a bug in the UIPopoverController. He gave me a workaround that kind of works but the right button in the nav bar ends up sliding across the screen after canceling the search. But, at least it fixes the issue. He also suggested I send in a bug report to Apple and I've done that as well. Hopefully they will fix this in the next version of the SDK.
Here's a copy of the relevant portion of the Apple engineer's response:
I've created my own project and dipped into what is going on and it looks like it's a bug in the UIPopoverController where after the UISearchBar is being dismissed, something is being obstructed in the navigation bar.
There's a workaround that I've found for now, though the animation that occurs is not amazingly optimal:
- Use the – searchBarCancelButtonClicked: method of UISearchBarDelegate and add the following:
self.navigationItem.rightBarButtonItem = nil;
self.navigationItem.rightBarButtonItem = self.editButtonItem;
As I said, it looks like the popover is pushing the button onto the navigation bar, so it may not be what you're looking for.
I tried the rightBarItem technique mentioned, but it didn't work for me. I had to do this (which is also a hack really)
[self.navigationController setNavigationBarHidden:YES animated:NO];
[self.navigationController setNavigationBarHidden:NO animated:NO];
This might be because my UINavigationBar isn't one unified with the popover, but I can't say for sure.