UITextView object is not being recognized in new controller

Viewed 40

I'm kind of new to Swift programming, so this question might look silly!

I have a new viewController named InfoViewController and I have connected it to the visual view controller in main.storyboard as the figure below:

As you can see, the view controller in main.storyboard is connected to InfoViewController.swift screenshot

However, when I insert the UITextView into the InfoViewController.swift, it does not recognize it as the following pic.

link of image

What is the problem, any help is highly appreciated

2 Answers

You can't just throw code inside the view... swift is function based... so you might want to create a function to call myText Label inside...

create this function on your class:

function changeMyLabelText(){
  self.myLabel.setText("New Text")
}

And call it inside viewDidLoad method with

self.changeMyLabelText()

You cannot access the outlet property on the from outside method. In viewDidLoad method you can easily access the myText outLet.

override func viewDidLoad(){
    super.viewDidLoad()
    myText.text = "something new"
}
Related