The cursor in the UITextView at the top is showing up completely fine, however the second UITextView just below it places the cursor 3-4 lines below it should be. So when I type anything in it, as shown in the screenshot below, it isn't right. The code for this view controller is shown below the screenshot.
class AddQuestionViewController: UIViewController, UITextViewDelegate {
@IBOutlet weak var questionTextView: UITextView!
@IBOutlet weak var answerTextView: UITextView!
@IBOutlet weak var doneBarButton: UIBarButtonItem!
@IBOutlet weak var questionLabel: UILabel!
@IBOutlet weak var answerLabel: UILabel!
weak var delegate: AddQuestionViewControllerDelegate?
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.questionTextView.layer.borderWidth = 0.5
self.questionTextView.layer.borderColor = UIColor.lightGrayColor().CGColor
self.questionTextView.layer.cornerRadius = 8
self.answerTextView.layer.borderWidth = 0.5
self.answerTextView.layer.borderColor = UIColor.lightGrayColor().CGColor
self.answerTextView.layer.cornerRadius = 8
self.questionTextView.becomeFirstResponder()
}
@IBAction func cancel() {
delegate?.addQuestionViewControllerDidCancel(self)
}
@IBAction func done() {
let item = Question()
item.question = questionTextView.text
item.answer = answerTextView.text
item.checked = false
delegate?.addQuestionViewController(self, didFinishAddingQuestion: item)
}
func textView(textView: UITextView, shouldChangeTextInRange range: NSRange, replacementText text: String) -> Bool {
if textView == questionTextView {
let oldText: NSString = questionTextView.text
let newText: NSString = oldText.stringByReplacingCharactersInRange(range, withString: text)
if newText.length > 0 {
doneBarButton.enabled = true
} else {
doneBarButton.enabled = false
}
}
return true
}
func textViewDidChange(textView: UITextView) {
let temp: NSString = textView.text
if textView == questionTextView {
self.questionLabel.hidden = temp.length > 0
} else {
self.answerLabel.hidden = temp.length > 0
}
}
func textViewDidEndEditing(textView: UITextView) {
let temp: NSString = textView.text
if textView == questionTextView {
self.questionLabel.hidden = temp.length > 0
} else {
self.answerLabel.hidden = temp.length > 0
}
}
}