John-Lluch / SWRevealViewController

A UIViewController subclass for presenting side view controllers inspired on the FaceBook and Wunderlist apps, done right !
Other
4.52k stars 989 forks source link

How do I control content from rearViewController? #491

Open darkgravity opened 8 years ago

darkgravity commented 8 years ago

Hi,

I followed this tutorial (https://www.youtube.com/watch?v=EWDNScxZ0YU) and I was able to make it work. However, I want to control for example the color of UILabel from the rearViewController. For example I tap on a list view item on the left that says "red", how do I make the UILabel on the frontViewController to red?

Thanks in Advance

-Pat

iDevelopper commented 8 years ago

Create a IBOutlet property with your label in your frontViewController and in prepareForSegue method (in the rearViewController), set the label's properties.

darkgravity commented 8 years ago

Thank you @iDevelopper , I think this method will reload the viewController. I want the same frontViewController to stay the same and only update the text. I already tried using segue, but it reloads the screen. I should be able to change just the text property without affecting the rest of the elements that I also edited. Is there a way to access fronViewController from the rearViewController without using segue?

iDevelopper commented 8 years ago

Ok

See here :

https://github.com/John-Lluch/SWRevealViewController/issues/487

darkgravity commented 8 years ago

Than you! I tried it but it still reload the viewController

here's my code in swift let storyboard = UIStoryboard(name: "Main", bundle: nil) let vc = storyboard.instantiateViewControllerWithIdentifier("ColorEditor") as! ColorEditorViewController vc.color1.oval.fillColor = UIColor.whiteColor().CGColor // This is where I edit a property self.revealViewController().pushFrontViewController(vc, animated: true)

I want everything to stay the same, except for the property that I want to edit.

iDevelopper commented 8 years ago

Have you deleted the segue in your storyboard ? And where did you place this part of code ?

iDevelopper commented 8 years ago

You need to have a property off your controller and instantiate it only if it doesn't exist yet ! Else, use the controller already instantiated... Sorry for my bad english...

darkgravity commented 8 years ago

Thanks @iDevelopper . I don't think it will work with this approach. What I need really is to make the rearView and the frontViewController without realoading the viewcontroller. Basically what my rearViewContoller is going to be a collection colorpalettes that I can show and hide as I please and these colors would change the color of my objects on the frontViewController. My frontview controller is not just a form but some form of Photo editor/canvas. I wan't my canvas to stay the same and just have one property when I tap on the toolbar nested on the rearviewcontroller.

iDevelopper commented 8 years ago

if (_controller == nil) { instantiate... self.controller = ... } push...

darkgravity commented 8 years ago

I was able to make it work! What i did is I created a dummy viewcontroller as my default frontViewController. What it does is trigger

self.revealViewController().revealToggle(self)

then I attached this to the viewDidLoad of the rearviewController

let storyboard = UIStoryboard(name: "Main", bundle: nil) vc = storyboard.instantiateViewControllerWithIdentifier("ColorEditor") as? ColorEditorViewController self.revealViewController().pushFrontViewController(vc, animated: true) now I have access to the properties of vc all the time :)

Thanks for the help!!!

iDevelopper commented 8 years ago

You can have a property of this controller in AppDelegate...