UITextView
が選択(タッチ)されたときにカーソルを移動して、UITextField placeholder
の種類をシミュレートしようとしました。UITextViewでカーソルを移動
私はカーソルを最初の行の先頭にしたいと思います。私の問題は、[someTextField setSelectedRange]
が確実に動作していないことです。私がtextView:shouldChangeTextInRange:replacementText:
でそれを呼び出すと、それはうまく動作します。しかし、このメソッドは、ユーザーが入力を開始したときにのみ呼び出されます。 UITextView
がファーストレスポンダになったとき、私は、カーソルを移動するtextViewDidBeginEditing:
を使用しています:
- (void)textViewDidBeginEditing:(UITextView *)textView
{
if (textView == self.descriptionText) {
CustomTextView* customTV = (CustomTextView *)textView;
if ([customTV.text isEqualToString:customTV.placeholder]) {
// text in text view is still the placeholder -> move cursor to the beginning
customTV.text = customTV.placeholder;
customTV.textColor = [UIColor lightGrayColor];
customTV.selectedRange = NSMakeRange(0, 0);
}
}
}
なぜcustomTV.selectedRange = NSMakeRange(0, 0);
textViewDidBeginEditing:
で正しく動作していない任意のアイデア?
ありがとうございました!
解決方法を見つけましたか? – Legolas