IBOutlet of another nil view controller

I have a viewviewcontroller that has objects in its view. I need to change the text to UILabel (in storyviewcontroller) and load the view into an array. I connected the IBOutlet to the label in the storyview manager.

class StoryViewController: UIViewController {
@IBOutlet weak var textLabel: UILabel!
@IBOutlet weak var inspiredButton: UIButton!

I created an object of the storyviewcontroller class and can access its variables. However, by creating the storyview dispatcher object, the IBOutlet is zero. Because of this, I get an exception that sends nil during deployment

let story:StoryViewController = StoryViewController()
story.textLabel.text = sampleText()

Could you help me with this! Here is a link to the whole project https://github.com/abhishekagarwal2301/DTC Thanks

+4
source share
1 answer

IBOutlets , , . view viewDidLoad ( )

class StoryViewController: UIViewController {
    @IBOutlet weak var textLabel: UILabel!
    @IBOutlet weak var inspiredButton: UIButton!
    var text:String!

   override func viewDidLoad() {
    super.viewDidLoad()

    textLabel.text = text
   }
}

,

let storyboard = UIStoryboard(name: "YourStoryboardName", bundle: nil)
var story = storyboard.instantiateViewControllerWithIdentifier("YourVCIdentifier") as StoryViewController
story.text = sampleText()
self.presentViewController(story, animated: false , completion: nil)
+4

All Articles