I orignally had a tab bar to change views within my app. However now I've gotten rid of the tab bar and have a toolbar with a menu button. When this button is pushed, a popover comes up with buttons that will hopefully change my screen.
When you create a UIPopoverController you set a UIViewController which can have a class where you define a protocol for the controller that creates the UIPopoverController notified of any action...
Related
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
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.
I have a View Controller where I perform a "search as you type". When I press on the SearchBar, hide the Navigation Bar, animated and I also show the scope buttons for my SearchBar. The problem is that when I press on a cell to push a new View Controller the Navigation Bar stays hidden. I KNOW I can set it unhidden, but it will animate from the top. I want to do something similar like in the Email app, when I press on a new cell, a new View Controller is pushed, and the Navigation Bar is animated from the right, like it belongs with the pushed View Controller. How can I make this happen?
Thank you.
Cosmin
Use the UISearchDisplayController to handle the search bar. The behavior you describe is the default behavior.
I have a root view controller with just a simple navigation button that loads a questionview. When I use pushViewController a back button appears. Instead I want a custom button in the top right of the uinavigationcontroller and I want to remove the back button after the page transition.
how can i achieve this..
Take a look at UINavigationItem. You can accomplish both your goals by properly configuring your view controller's navigation item. Use the -setHidesBackButton:animated: to hide the back button, and the -setRightBarButtonItem:animated: to add your custom button on the right side of the navigation bar.
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.