Storyboards, UITabBarController and SWRevealViewController - ios

I have a storyboard that uses a UITabBarController with 3 tabs.
I want to use SWRevealViewController to add the sliding menu functionality.
Opening the menu will slide the hole UITabBarController.
Did anyone managed to implement this kind of behaviour with storyboards UITabBarController and SWRevealViewController?
Thank you

Managed to integrate it. Below are the steps to do it:
Add a new UIViewController to the storyboard.
Remove the content view from the newly added UIViewController
Make sure "Is Initial View Controller" is checked in IB for the newly added UIViewController
Set the custom class for the newly added UIViewController to SWRevealViewController
Connect it to a view controller that you intend to be the rear view controller - give the segue "sw_rear" identifier in IB. This must be a reveal controller segue type.
Connect it to the UITabBarController - give the segue "sw_front" identifier in IB. This must be a reveal controller segue type.

You should use a navigation controller before tab bar controller(sw_front > navigation controller > tab bar controller).

gfdx answered his own question, but make sure to also look at this tutorial for more insight on how to hook up everything else correctly.
Because I'm using Core Data and I was told that calling
[[NSApp delegate]managedObjectContext];
is not a good idea, I pass in my data controller class to the views in AppDelegate.m. Since I'm now using the SWRevealViewController instead of my subclass of UITabBarController, I had to make some modifications.
SWRevealViewController performs some interesting behaviors on load, one of which is loading the dependent view controllers by calling the segues. Be aware that if you make changes in your subclassed prepareForSegue:sender: method, make sure to always, always call the super's method, otherwise you'll end up with a black, blank application.

Related

Reusing the same viewController on top of the navigationStack in swift

For my app project i have created a tableView that show a wine including, rating reviews, tasting notes and all sorts of data in each section. In the last section the user is shown two similar wines, once pushed it is the purpose to reUse the current viewController, and throw it onto the navigation stack as the user might browse another wine inside that viewController and so forth.
How would you go about, reUsing the same viewController. Since building infinite numbers of the same viewController in storyboards seems abit rookie to me. Thanks all help appreciated.
You can use Storyboards and reuse the ViewController with no problem.
In the Storyboard use the Storyboard ID in the identity inspector, Add a unique ID to the ViewController.
After that it's pretty simple, you can ether:
Instantiate the first level viewController with the segue, than once you want to add another ViewController (of the same type) with the UIStoryboard instantiateviewcontrollerwithidentifier: and give the unique id of the ViewController, and present it
or
You can just use the UIStoryboard instantiateviewcontrollerwithidentifier: every time you want to present the ViewController
If you want to use storyboard, there is a hack (a bit dirty).
You should add button to view controller. But not to the view of
view controller, you should add it to the top section (top bar) of
your view controller.
Then you add segue from this button to this very view controller.
Now you may use this segue from code (performSegue...)

How to use segues from view controller that has a XIB for it's design?

I'm implementing a navigation hierarchy in a storyboard. For part of my navigation, I am drilling down through a tree of data, so I have a couple view controllers in a row with the exact same look but different data management so they need separate controllers. To avoid duplication I did the layout for those views in a XIB, made a VC class for the XIB to handle setting up the views, and then I extend that class for each VC in the storyboard to handle the UITableViewDataSource stuff.
Now the navigation is working fine, but I want to have a button on the XIB views that triggers an unwind segue back to the beginning. I have the segues set up with identifiers in the storyboard from my VCs with a XIB layout to the home screen, but no matter what I do, when I call performSegueWithIdentifier I always get the has no segue with identifier error.
I think what's going on is that everything extra added to the view controller in the storyboard is removed when the XIB is loaded. I found that that was happening with my navigation item in these views and I had to create the navigation item in code since there's no way to add one in a XIB. I suspect something related is happening with the segues, but I can't figure out a workaround. Is it just not possible to have a VC in a storyboard with its layout in a XIB and then perform a segue from it? Is there a programmatic way to do an unwind segue without setting it up in the storyboard?
Unwinding is only available if you are using storyboard. So in your case you have to use UINavigationController.popViewControllerAnimated or UIViewController.dismissViewControllerAnimated:completion:.

Reuse childs from custom UIVIewController using storyboard

I have a storyboard with a navigation controller that leads to an UIVIewController that I want to reuse. That UIVIewController has a ParentUIViewController that has all the basic functionalities for all the UIVIewControllers that I am reusing.
Currently I am copying and pasting (meh) and then I change the class of the UIViewController to the ChildUIVIewController that I want to use (ChildUIViewController extends ParentUIViewController).
But this sounds like a bad solution. Everytime I want to change the ParentViewController visually I need to update, manually, all other ChildViewControllers.
I have tried to create a xib for the ParentViewController but the xib isn't loaded because I need a xib with the name of the ChildViewController. I have created it and then said the class is the ParentViewController but it crashes in the segue.
EDIT
I have created an example of the status of my problem
https://github.com/tiagoalmeida/storyboardexample
Note that the ParentViewController has a set of logic way more complicated that is not illustrated there. Also note that I am also using a TableView. I hope that this can illustrate the problem.
Keep the logic on the parentViewController and the UI Part on the child UIViewControllers. If you need to create a new UIViewController, you will create a child that will have a corresponding XIB (or get rid of XIBs and create the interface by hand).
Have you considered looping back into the same UIViewController via a "phantom button"?
Have a look at this: UIStoryboard Power Drill, Batteries included
Essentially you can drag a Bar Button Item into the little black bar under the View Controller in Storyboard (the 1 with View Controller, First Responder, and Exit icons; sorry, I don't recall what this is called exactly), then you can control+drag from that button back into the UIViewController for a Push segue. This should create a loop segue in your Storyboard. All you need to do next is give that segue an identifier, programmatically call it from your code using [self performSegueWithIdentifier:], then implement -(void)prepareForSegue: and use [segue destinationViewController] to conditionally set the title and perhaps some flags so you can identify when to use different kinds of fetches (or other code variations) in the same Class code.

iOS App ECSlidingViewController: add new viewcontroller and transient to it

I use ECSlidingViewController in my App. There're four ViewControllers come with the sample code. These four ViewControllers corresponds to four option in the "MenuViewContoller".
Now I want to add a TableViewController in the "FirstTopViewController". Each cell of this TableViewController leads to a ViewController which is not one of the four predefined ViewControllers.
I saw that ECSlidingViewController ships a 'SampleTableViewController". But I don't know how to 'transient' to this ViewController.
I did work with UINavigationController before. I know how to push a view controller to NavigationController. I don't know how to cooperate UINavigationController with ECSlidingViewController.
Thanks a lot.
Here is a demonstration:
http://www.penghou.net/file/question.png
ECSlidingViewController is a container, just like UINavigationController. You give it view controllers and it displays and transitions between them.
ECSlidingViewController provides methods for setting view controllers and transitioning between them by calling anchor/reset. Check the header file for documentation on these methods.

Dynamically created buttons and storyboard segue

I'm stuck because of this problem in my code:
I am using a storyboard, and have my custom tableview that is able to swipe rows uncovering the "background" where I can add buttons etc.
Problem is that the number and presence at all is managed in runtime (each cell can have multiple buttons or none - I'm adding them to the background view). Now I want these buttons to segue and I just cannot figure out how to do it in my storyboard...
Anyone had similiar problem or I'm just thinking wrong?
Another way to do this is to go ahead and create the segue's in the storyboard. You can't connect them to the button (since it doesn't exist yet), but you can connect them to the view that the table is in. You give the segue an identifier (by clicking on the line that is the segue and setting the property). Then, it is a simple matter of calling:
[self.storyboard performseguewithidentifier:#"theIdentifier"];
you can't make segue connections outside of the storyboard:
Creating a segue programmatically
You can make custom segues in code, but connecting the segues up to objects can only be done by drawing lines on the Storyboard.
But you don't need to. Segues are only dressed-up transitions between viewControllers. They are a visual tool for replacing a small amount of code.
A push segue just replaces this code for example
UIViewController* myViewController = [UIViewController alloc] init;
[[self navigationController] pushViewController:myViewController
As you are making your buttons in code, you should manage your navigation in code.
First of all you need to set the StoryBoard ID. You can do this by selecting a particular view controller and going identity inspector on the right side. Under the custom class, there is "StoryBoard ID", you have to set name "Menu"
Secondly, you need to call this storyboard from the buttons or any other control.You can do this by using the following:
[self.storyboard instantiateViewControllerWithIdentifier:#"Menu"];
This way you can give StoryBoard IDs to different controllers in your StoryBoard and call them from whatever control you want.
Hope this helps

Resources