iOS App ECSlidingViewController: add new viewcontroller and transient to it - ios

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.

Related

Storyboards, UITabBarController and SWRevealViewController

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.

Set up UITabBarController with three other view controllers

I have a UITabBarController inside of a TabBarViewController. I want to use this to connect my three other view controllers to a tab bar.
What I have so far: I have my three view controller, each with one UIView inside of them, ready to be paired with the tab bar to give easy navigation between them. I have also made a new Objective-C class of type UITabBarController. Inside the .xib of that I deleted the UIView and replaced it with a UITabBarController (not sure if this is right).
I'm new to Objective-C and Xcode so I don't know a whole deal about it all, so I may be doing this all wrong. Please correct me and try not to be too vague, thank you!
There's a tutorial here with two tabs:
http://www.youtube.com/watch?v=NfEK9JsCyXM
You can watch it and work with it to make it do 3 tabs.

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.

UIViewController in a UIScrollView in a UINavigationController wants to push a new Controller

I've got a stupid UI Problem right now with one of our apps.
I start with a UINavigationController which is the Initial View Controller in my Storyboard. The Root view controller is a UIViewController witch a UIScrollView as subview. The UIScrollView itself has paging enabled and contains several UIViewControllers.
Now here is my problem: The UIViewControllers (lets call them View #1) in the UIScrollView should react to a button event and make a segue to another UIViewController (View #2) which needs to get data from the previous UIViewController and needs to send data back by delegate methods.
When I try to get the UINavigationController and push View #2 on it, nothing happens. Showing it via presentViewController of course works.
Could you just help me a little bit, tell me that this doesn't work and when not why? I'm a little bit stuck at this point and i don't know how to proceed.
DO NOT put UIViewControllers inside another UIViewController (atleast pre iOs5) that goes against apples development guidelines ..
The UIViewControllers life cycle is managed internally and if you directly add the UIViewController as a subview a lot of methods such as
viewDidLoad
viewWillAppear
viewDidAppear
.
.
.
will not be called and from my experience will lead to really erratic behavior
Try and use custom UIView objects to get your internal logic for each view
agreed this somewhat breaks the MVC pattern but this would be the best way to go about your issue
But iOS 5.0 added containment UIViewControllers that correctly handles those lifecycle events by adding child view controllers. so if you are targeting only post iOs 5 devices this maybe a good way to about it
Have a look at this and this

Sharing the Same UIViewController as the rootViewController with Two UINavigationControllers

Update: I have decided to go a different route with my problem.
Instead of trying to reuse the same UIViewController directly, I use two vanilla UIViewControllers that are set as rootViewControllers. In their loadView methods, they make a call to [storyboard instantiateViewControllerWithIdentifier:] to get the former UIViewController and set their views to the controller's view. This is probably the preferred approach anyway, since I need to set several variables and delegates.
I have a UIStoryBoard with a UITabBarController as the entry point connected with two UINavigationControllers. Each of those share a common UIViewController as their root view controller. When the app starts, the first UITabBarItem is selected and the view loads as-expected. However, when I select the second UITabBarItem, the same view is not visible. I see the UINavigationBar with a black background. Am I doing something incorrect with the Storyboard interface, or do I need to manually instantiate the UIViewController via each UINavigationController's method--loadView for instance?
Strangely this is a question that no one else is asking. As far as I know it is not possible to share the rootViewController which I think is without a doubt a bug since when you inspect the connection on the storyboard you can see that the view controller is connected to both navigation controllers. I consider this a flaw in storyboarding because duplicating viewControllers and reapplying all of their connections is quite error prone and makes the storyboards overly complex.
I see your solution to the problem. Workarounds like this make me question if the current storyboard functionality in iOS is ready for creating apps. I think that there is a conceptual problem with the storyboards, Apple needs to decide if a viewController on a storyboard represents an instance or if it represents just the class, right now it is not consistent as you can see that multiple segues can actually point to the same viewController but in reality each segue has its own instance, why this is not also followed for rootViewController connections?, I don't know.
Just as a note, with your solution take into account the following from Apple's documentation:
"Important A view controller is the sole owner of its view and any subviews it creates. It is responsible for creating those views and for relinquishing ownership of them at the appropriate times, including during low-memory conditions and when the view controller itself is released. If you use a storyboard or a nib file to store your view objects, each view controller object automatically gets its own copy of these views when the view controller asks for them. However, if you create your views manually, you should never use the same view objects with multiple view controllers."
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html
Definitely a bug in Storyboards. Another way to do this is to create basic UIViewControllers for each UINavigationController, then have a UIContainerView that points to the same UIViewController in each of the basic view controllers.
I think the easiest solution is to set no root view controller for your nav controller in the storyboard and then do something like this with your nav controller:
- (void)viewDidLoad
{
[super viewDidLoad];
UIViewController *topVC = [[UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:#"myTopVC"];
[self pushViewController:topVC animated:NO];
}
The first-pushed VC becomes the root.

Resources