Yuri Jose
Yuri Jose

Reputation: 33

ViewController don't access your elements

I have a class that ViewController.swift linked to a UIViewController in my storyboard:

enter image description here

I have another class called ExpandableViewController and in it I try to resend ViewController:

    var viewController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("ExpandableViewController") as UIViewController
    self.presentViewController(viewController, animated: false, completion: nil)

But my viewController variable can not access the variable button in this class ViewController.swift am unable to create this subclass in ExpandableViewController.

How could I do that?

Upvotes: 0

Views: 40

Answers (1)

Peter Todd
Peter Todd

Reputation: 8651

Couple of issues:

var viewController:UIViewController

should be

var viewController:ViewController

You have subclassed UIViewController as ViewController

It would also be a good idea to give ViewController a storyboard id that is not the same as your other custom class (ExpandableViewController).

You will want to do something like:

 let viewController:ViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("ViewController1") as! ViewController
    self.presentViewController(viewController, animated: false, completion: nil)
    viewController.button.setTitle("TEST", forState: UIControlState.Normal)

Upvotes: 1

Related Questions