Maintaining popover across multiple detailviews in UISplitView - ios

In my app delegate I create a UISplitViewController. I set the delegate to be the detailViewController.
When I run my app in portrait, I have the left top popover button showing that will slide out the split view master.
Then I have a button in my detail view that resets the splitviewcontroller array with a new detail view controller and sets the split view delegate to that controller.
The second detail view displays properly... but I lose my popover button on the second view controller.
Does anyone know how I can get that button to remain on all of my detail view controllers I may add?
Thanks!

See http://www.raywenderlich.com/forums/viewtopic.php?f=2&t=1546 for what I find to be a good approach.
It involves setting the SplitViewController delegate to be the master instead of the detail. The master keeps references to the popoverController and the button, and each time the delegate methods are called (hide and show master) it gets the current detail view and performs the necessary action (add in the button/remove button and popovercontroller).
The master defines a protocol for "SubstituableDetailView" which contains the two methods for showing/hiding the button.

Related

NavBar doesn't appear when segue is called programmatically

I have an iOS app with 3 views. I am using a "push segue" to move between them. I have linked a push segue from a button in First view to Second View. For moving from second to third, I cannot have a button. I have a list of items and the person can click in any of those to move to third(and last) view. So I added a segue in storyboard and calls it programmatically. The third view is opening properly except that the nav-bar is no longer there.
[self performSegueWithIdentifier: #"moveToFilesSegue" sender: self];
I can live without nav-bar. But the real problem is that I cannot do a push segue from my third view to any other view.
So my question is whether there is a way to call a segue from second view to third view in such a way that the third view also has the navigation controller that the first two have by default(ie navbar is also visible in third segue). There is some break in navigation because of me calling a segue programmatically.
So a few comments. If you would like to be able to get to the two other views from any view at any point in time, then I would suggest using a tab bar controller rather than a navigation controller.
If you must use a navigation controller, then you should keep the first view controller as the root view controller. Imagine then tapping a button that pushes the second view controller. Then say you tap a button to get to the third view controller from the second. What you should really do is perform an unwind segue from the second and then immediately perform a segue to the third. The animations will be a bit undesirable by default since it will probably show the pop and the push, but to treat it like a tab bar, you could just disable the animations on the pop and push.
To implement, keep an int variable in the first view controller (btw.. you can do this by keeping the int in the navigation controller as well if you want). In the viewDidAppear, check the int variable. If it == 1 then push the second view controller. If it == 2, then push the third view controller. Else, don't do anything. When a button is pushed in the second view controller to view the third, unwind the second view controller, but in prepareForSegue set the int variable in the destination view controller to 2 . Thus, when the first view controller appears, it will immediately push the third view controller.
I know it is a bit annoying, but you don't really want to keep pushing the same view controllers over and over again without unwinding.

The TabBarItem disappear when I push in other view

I have a TabBarApplication with four views in the main TabBarItem. The problem comes when I go to any of these views and click in any button to go to another view and when I go back by a button linked to the main view, the TabBarItem of the app disappear!!
For example, one view of the app is a tableView in which each element of the list is linked to his external view and it has a back button that should return to the tableView. All the segues are by modal, not push because push segue crash the application and by modal it runs correctly but the problem comes when I returned by clicking the back button of the NavigationItem in the header of the view to his main view and the TabBarItem of the app is not there, is empty.
Each tab should have the view controller set to a navigation controller, with the view controller you want set as the root view controller of the navigation controller. Now you can use push segues and the standard back button that will be added for you. This will bypass the issue (and work much better for you and users).
You current issue is likely related to not really ever going back. Instead, just always presenting new modal view controllers which replace any existing content on screen.

Swiping between UITableViewController detail items

I have a UITableViewController derived class. In tableView:didSelectRowAtIndexPath:, I create a detail view controller vc and push it with [self.navigationController pushViewController: vc animated: YES];.
On that detail view, I want to be able to swipe left and right and go to the previous/next item detail, or back to the table view if it's on the first/last item. I implemented the swipe and back functionality using [self.navigationController popViewControllerAnimated: YES];, but I'm not sure about how to implement the detail -> detail paging. I thought about using the same pop, then calling tableView:didSelectRowAtIndexPath:, but tracking and modifying the index path and tracking the tableView seems like a clunky way. Is there a better way?
Also, when I pop the view controller, it always slides off to the right. Is there a way to animate it sliding off to the left (to simulate a right to left swipe on the last item)?
The best way to do what you're trying to do is to present your detail contents in a UIPageViewController. It is a collection view controller, kind of like a table view controller. It has a delegate and data source like a table view does. It asks you to give it view controllers that present pages of content. You can set it up to slide from page to page or page curl, and optionally add a book spine. There is a sample app from Apple called PhotoScroller that shows how to set up a page view controller for sliding back and forth. It does a lot more than that, but you can ignore the content view controllers it uses and substitute your own detail view controllers.
You would share the data model between the table view and the page view controller.

Creating an initial view before displaying views with UITabController

I am creating an app that uses a UITabController with 5 tabs for navigation. Right now my app loads the first tab as the initial view upon app loading.
I want to be able to change that so I have a view that doesn't use my UITabController as the initial view, and once they click the one button on it, it brings them to the First View and displays the TabController.
I thought I'd simply set up a new view, change that one to the initial view controller and have a segue from the button to the TabController, but when I tried that and the view I wanted to with the button loaded first, but when clicking button it said something about needing to set up a NavigationController? Not sure what to do from here.
I think it's best to leave your tab bar controller as the window's root view controller. You can present the initial view controller from the viewDidAppear method of the controller in the first tab, using presentViewController:animated:completion:. Do this with the animated parameter set to NO, and the initial view will be the first thing the user sees. When you're done with that view, just dismiss it, and you'll be back to the first tab's view.

How can I resize views inside a navigationcontroller inside a popover?

I have a popover that gives a list of options to the user, and when the user clicks it pushes another view onto the stack. This works fine for the first view, but once one of the larger views is opened, the popover window won't shrink down to size when the user backs out of the navigation workflow. I've tried calling sizeToFit on the child views and on the navigation view, but it doesn't seem to have an effect.
How can I make sure the popover and navigation controller are the correct size for the current view being shown?
Normally in this type of workflow, let's say you start with VC1. From VC1, you present a popover to user with selection choices. User makes a selection from the list (a tableview, etc.) You then need to (from the popover) make a callback to VC1 and pass back along any data which in this case user's selection to VC1. VC1 then dismisses the popover and then prepares another view controller with that data and push the new view controller on to the display/navigation stack. That is a pattern I would use.

Resources