CosmicMind / Material

A UI/UX framework for creating beautiful applications.
http://cosmicmind.com
MIT License
12k stars 1.26k forks source link

SideNavigationViewController example #74

Closed WooD1k closed 8 years ago

WooD1k commented 8 years ago

Hello!

May you please create a simple sample project that uses SideNavigationViewController? I'm trying to use it, but can't understand how should it work :)

I event can't use it as is explained at repo README.md Just getting a black screen, but according to the storyboard this screen should be white and should contain 'touch me' button

I've created a sample project, so you will be able to 'reproduce' my failure :)

Here is the link to my repo with the sample - SideNavigationViewControllerTest Please let me know if i may provide some additional information. Thanks in advance!

adamdahan commented 8 years ago

Hi @WooD1k,

There is an issue with your approach:

When creating an iOS project you have three choices

  1. Using a template
  2. Start with an empty project and add a storyboard or xib.
  3. Pure code no storyboards

Based on your sample project SideNavigationViewControllerTest it seems you started the project with either 1 or 2 from the choices above.

The issue to your approach was this piece of code:

window = UIWindow(frame: UIScreen.mainScreen().bounds) window!.rootViewController = SideNavigationViewController(mainViewController: ViewController(), sideViewController: SideMenuViewController()) window!.makeKeyAndVisible()

Click on the Blue project file and then click on the app name under "Targets"... Look at the "Deployment Info" you will see that you have "Main" set under "Main Interface"

You are using storyboards so the code in appDidFinishLaunchingWithOptions wont work for you because it is using that "Main" storyboard file for the "Main Interface" of the project. So no need to override the window's rootViewController property because that's already happening in the background.

To fix your issue:

Step 1. You will need to drag a view controller from Interface Buildings Object Panel and change the class to "SideNavigationViewController" just like you would with another subclass of UIViewController.

Step 2. The only thing then left to do is assign a view controller to the SideNavigationViewController's mainViewController property. That can be done via dragging an outlet from IB or programmatically. The mainViewController property here represents the view controller you want to appear in the center.

Step 3. Make sure you deleted the code in appDidFinishLaunchingWithOptions

Hope that helps!

:)

WooD1k commented 8 years ago

Hello @adamdahan

Many thanks for your detailed answer!

I've added a new view controller from object panel, changed class to SideNavigationViewController and there is no any properties at outlets section(main or side), here is the screenshots:

main storyboard edited 2015-11-30 12-25-00 main storyboard edited 2015-11-30 12-27-19

Thanks in advance!

adamdahan commented 8 years ago

Hey @WooD1k,

I see the issue now. There is no IBOutlet property for the mainViewController. We don't use storyboards much ourselves but we will definitely make that available in a future update.

To remedy your situation for the time being until the next release:

Click on the Blue project file and then click on the app name under "Targets"... Look at the "Deployment Info" and delete the file "Main" set for the "Main Interface" and do it programmatically.

Just replace the identifiers below and put this in your appDidFinishLaunchingWithOptions ->

let storyboard = UIStoryboard(name: "Main", bundle: nil) let mainVC = storyboard.instantiateViewControllerWithIdentifier("YourViewControllerIdentifier") let sideVC = storyboard.instantiateViewControllerWithIdentifier("YourSideViewControllerIdentifier") window = UIWindow(frame: UIScreen.mainScreen().bounds) window?.rootViewController = SideNavigationViewController(mainViewController: mainVC, sideViewController: sideVC) window?.makeKeyAndVisible()

Closing this ticket for now and turning into a "Support Storyboards" ticket. Feel free to keep on messaging us about your issue we always do our best to help you resolve it. Hope that helps and we will push the support you need in the next update!

Cheers

adamdahan commented 8 years ago

@WooD1k you can track the storyboard support ticket here: https://github.com/CosmicMind/MaterialKit/issues/75

WooD1k commented 8 years ago

@adamdahan many thanks!

adamdahan commented 8 years ago

@WooD1k my pleasure.

And just a side note: The above fix allows you to keep doing your work in storyboards. The only programmatic thing done is passing the rootViewController to your apps window. So basically you don't need to do the dragging in IB to hook up the SideNavigationViewController. Just do that part programmatically and use the storyboards as you wish for the individual view controllers in your app.

:)