Bryan Campbell
Bryan Campbell

Reputation: 285

UITextView will not set text

I am having trouble setting the text in my UITextView. My textView is connected to my storyBoard. I control dragged to create my outlet.

import UIKit

class ViewController: UIViewController, UITextViewDelegate {

@IBOutlet weak var textView: UITextView!
override func viewDidLoad() {
    super.viewDidLoad()
    textView.delegate = self
    // Do any additional setup after loading the view, typically from a nib.

    textView.text = "hello"
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
func textViewDidChange(_ textView: UITextView) { //Handle the text changes here
    print(textView.text); //the textView parameter is the textView where text was changed
}

}

I expected the string "hello" to appear in the view controller on my simulator but instead I just have a blank screen. Why don't I see the string?

Upvotes: 2

Views: 5866

Answers (2)

Amal T S
Amal T S

Reputation: 3415

Check if the textcolor is same as textview's background color.

Upvotes: 0

davidethell
davidethell

Reputation: 12038

Your textview is working fine as far as setting the .text value. The reason it doesn't appear is that your textview has some auto layout constraints missing.

Add a width and height to your textview and it will work.

Upvotes: 8

Related Questions