Ehsan Ghasaei
Ehsan Ghasaei

Reputation: 183

UITextView object is not being recognized in new controller

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 😊

Upvotes: 2

Views: 43

Answers (2)

Faysal Ahmed
Faysal Ahmed

Reputation: 7669

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"
}

Upvotes: 0

Guilherme Vallone
Guilherme Vallone

Reputation: 39

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()

Upvotes: 1

Related Questions