Reputation: 665
I was looking at Text View Placeholder Swift. And it seems to me that I did everything that this post has told me to do. However, it is not working. More specifically, the textViewDidBeginEditing()
and textViewDidEndEditing()
functions are not executing. And the reason why I think this is because I wrote the println("hello")
and println("YO")
but it is not printing anything to the console. Anybody have a solution to fix this problem?
Here is my code:
import UIKit
class WritePrayerRequestViewController: UIViewController, UITextViewDelegate {
@IBOutlet weak var writePrayerRequestTextView: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
writePrayerRequestTextView.becomeFirstResponder()
writePrayerRequestTextView.layer.borderWidth = 0.5
writePrayerRequestTextView.layer.borderColor = UIColor.lightGrayColor().CGColor
writePrayerRequestTextView.layer.cornerRadius = 7
writePrayerRequestTextView.textColor = UIColor.lightGrayColor()
writePrayerRequestTextView.text = "Write your prayer request here."
}
func textViewDidBeginEditing(writePrayerRequestTextView: UITextView) {
println("hello")
if writePrayerRequestTextView.textColor == UIColor.lightGrayColor() {
writePrayerRequestTextView.text = nil
writePrayerRequestTextView.textColor = UIColor.blackColor()
}
}
func textViewDidEndEditing(textView: UITextView) {
println("YO")
if textView.text.isEmpty {
textView.text = "Write your prayer request here."
textView.textColor = UIColor.lightGrayColor()
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Upvotes: 1
Views: 209
Reputation: 11597
are you sure the UITextView's delegate is assigned correctly? eg writePrayerRequestTextView.delegate = self
in the viewDidLoad
Upvotes: 1