Android Conductor - how to insert one controller to another as view? - conductor

I have some controller classes with own implementations. Is it possible to insert one to another as view in viewgroup?

Yep, this is what child controllers are. From the readme:
getChildRouter can be called on a Controller in order to get a nested Router into which child Controllers can be pushed. This enables creating advanced layouts, such as Master/Detail.

Related

NavigationBarViewController Storyboard example

I want to build my layout using storyboards but also use the implementation of Material. But I have trouble to understand how to use the NavigationBarViewController with Storyboards.
Can you create an example for Storyboard using the NavigationBarViewController with transition between views? Is it possible to use segues?
Your question is a little vague, but yes, you can segue (and usually do in any complex app) between views while contained in a navigation controller. The navigation controller will persist between these views unless you are segueing using modals.

How to implement a SideNavigationViewController into a UIViewController?

A little confused on how to implement this into my main view controller. The example project shows it as a navigation controller, but I wasn't able to add an existing class on a fresh navigation controller or my current UIViewController. I could just be implementing it wrong though. Much appreciation if I can gain some traction on how to work with these.
If you could share some code that would be great.
How things work:
Navigation Controllers
There are currently 4 different Navigation Controllers that each offer their own features. The controllers can be used individually, or together.
SideNavigationViewController
The SideNavigationViewController offers 3 bodies to display content: mainViewController, leftViewController, and rightViewController.
MainViewController
The mainViewController must always exist, and has a facility for transitioning between view controllers using the transitionFromMainViewController method. Using this method is as easy as passing a UIViewController in its first parameter.
sideNavigationViewController?.transitionFromMainViewController(InboxViewController())
There are further parameters that allow for animations, completions, etc... to be set when transitioning between view controllers.
LeftViewController and RightViewController
The leftViewController and rightViewController can be set only once. To make them dynamic, you would need to use another Navigation Controller as its view controller.
NavigationBarViewController
The NavigationBarViewController offers a NavigationBarView along side the ability to manage two UIViewControllers, the mainViewController and the floatingViewController.
MainViewController
The mainViewController is like the SideNavigationViewController's mainViewController, and has a transitionFromMainViewController method that transitions from view controller to view controller in the body portion of the NavigationBarViewController.
FloatingViewController
The floatingViewController is a modalViewController and when set, it pops over MainViewController and NavigationBarView. Setting that value is like so:
navigationBarViewController?.floatingViewController = InboxViewController()
To close and hide the floatingViewController set it to nil, like so.
navigationBarViewController?.floatingViewController = nil
SearchBarViewController
The SearchBarViewController offers a single transitioning mainViewController, as well, has a SearchBarView at the top. Transitioning the mainViewController is like so:
sideNavigationBarViewController?.transitionFromMainViewController(InboxViewController())
MenuViewController
The MenuViewController is another controller that has a mainViewController, which takes the entire screen. Floating above it, is a MenuView that is used to transition between mainViewControllers.
menuViewController?.transitionFromMainViewController(InboxViewController())
Final Notes
These Navigation Controllers can be used in any combination and any amount of times creating a robust and intricate stack of controllers that act like one.
I hope this helps :)

Can you pass a TreeController between views?

I have a standard Master-Detail Interface and I'm using Coredata and cocoa bindings.
The Master list uses a NSOutlineView and a NSTreeController, these items remain static but different details views are swapped in and out.
So, how do I set the content of the array controllers in the different detail views to correspond to the selection in the outlineview in the Masterview?
This is straight forward if all the array/treecontrollers are in the same .xib file. initially, I tried creating an Outlet from of the Treecontroller and passing this to the orther views as they are created, but I don't think this is correct.
Any suggestions?
You can use an array controller or a tree controller for as many views as you like. In your specific example, I would make the masterview owner of the tree-controller (unless you have a compelling reason to go yet another level up). Then each detail view that gets swapped-in would also have view controllers. That controller would have an assignable "tree-controller" property that would get set before its view is loaded to the value of the "master" tree-controller. Within the Nib files you can use bindings (to the tree-controller of files-owner) as you normally would.

What is the correct way to switch between UIViewControllers without using a navigation controller or loading views modally

I'm trying to accomplish switching views without using a navigation controller, tab bar controller etc. I am currently accomplishing this using Cocos2d director class replaceScene method. My application will need to have around 40 view controllers, each with a few UIButtons that could take them to any other view controller.
For instance View controller 1 may have buttons that take you to view controller 2
View Controller 2 may have buttons that link to 3,4,5,12
view controller 4 may need to link to view controller 17, 5 and 3
Every tutorial and bit of documentation I've read only discusses using Navigation Controllers, Tab bars or pushing views modally. None of these solutions fits my particular requirements.
Cocos2d has the "replaceScene" method which does exactly what I need, but mixing the many UIKit controls that I need makes developing this entire project in Cocos2d a nightmare.
I'm looking for something where I can have the user tap a button which will load a specified view controller/view transition to that view, and unload the previous view controller from memory. Any ideas?
Have a root view controller which has references of your view controllers. Also make a weak reference to the root view controller in each view controller, as in a delegate pattern. If one of the view controllers wants to make a view transition, send a message to the root view controller. Let the root view controller hide the current view and unhide the next view, using an animation if you want.
Basically you are implementing a view container much simpler than UINavigationController and UITabBarController. You could probably achieve the same thing using the tab bar controller and hide the tab bar view, but I would implement a custom one.

MVC basics: Should I add a UIViewController, a Delegate or a Source to my custom view?

my question is about view controllers, delegates and all that in general. I feel perfectly comfortable with UIView, UIViewController, Delegates and Sources, like UITableView does for instance. It all makes sense.
Now I have implemented my first real custom view. No XIBs involved. It is an autocomplete address picker very much like in the Mail application. It creates those blue buttons whenever a recipient is added and has all the keyboard support like the original.
It subclasses UIView. There is no controller, no delegate, no source. I wonder if I should have either one of those? Or all, to make it a clean implementation.
I just cannot put my finger on the sense a view controller would make in my case. My custom view acts much like a control and a UIButton doesn't have a controller either.
What would it control in my view's case?
Some of my thoughts:
For the source: currently the view has a property "PossibleAutocompleteRecipients" which contains the addresses it autocompletes. I guess this would be a candidate for a "source" implementation. But is that really worth it? I would rather pass the controller to the view and put the property into the controller.
The selected recipients can be retrieved using a "SelectedRecipients" property. But views should not store values, I learned. Where would that go? Into the controller?
What about all the properties like "AllowSelectionFromAddressBook"? Again, if I compare with UIButton, these properties are similar to the button's "Secure" property. So they are allowed to be in the view.
The delegate could have methods like "WillAddRecipient", "WillRemoveRecipient" and so on and the user could return TRUE/FALSE to prevent the action from happening. Correct?
Should I maybe inherit from UIControl in the first place and not from UIView?
And last but not least: my custom view rotates perfectly if the device is rotated. Why don't all views? Why do some need a controller which implements ShouldAutoRotateToDeviceOrientation()?
Does it make sense what I wrote above? In the end I will provide the source on my website because it took me some time to implement it and I would like to share it as I have not found a similar implementaion of the Mail-App-like autocomplete control in MonoTouch.
I just want to learn and understand as much as possible and include it in the source.
René
I can answer part of your question.
I just cannot put my finger on the
sense a view controller would make in
my case
The ViewController is responsible for handling the View's state transitions (load, appear, rotate, etc) These transitions are used mainly when you use a navigation component (UINavigationViewController, UITabBarController). These components needs to received a ViewController that will handles the view's transitions.
For exemple, when you push a ViewController on a UINavigationViewController, it will cause the ViewDidLoad, ViewWillAppear, ViewDidAppear. It will also cause the ViewWillDisappear, ViewDidDisappear of the current ViewController.
So, if your application has only one portrait view, you don't need a ViewController. You can add your custom view as a subview of the main window.

Resources