重複の可能性:
カーソルを UITextField の先頭に移動する
こんにちは、テキスト付きのテキストビューがあります。最初にカーソル位置を移動したいのですが、NSMakeRange を使用していますが、なぜ機能しないのかわかりません。私は NSMakeRange is different places を書きましたが、少なくとも一度は実行されることを期待していますが、うまくいきませんでした。これがコードです。thx事前に
- (void)viewDidLoad
{
[super viewDidLoad];
apnatxtView.textColor=[UIColor lightGrayColor];
apnatxtView.text=@"Description goes here";
totalLenght=apnatxtView.text.length;
apnatxtView.selectedRange=NSMakeRange(0,0);
}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
apnatxtView.selectedRange=NSMakeRange(0,0);
return YES;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[apnatxtView resignFirstResponder];
}
- (void)textViewDidChange:(UITextView *)textView{
if (apnatxtView.text.length == 0) {
apnatxtView.textColor= [UIColor lightGrayColor];
apnatxtView.text=@"Description goes here";
apnatxtView.selectedRange=NSMakeRange(0, 0);
}
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
if (apnatxtView.textColor == [UIColor lightGrayColor]) {
apnatxtView.textColor=[UIColor blackColor];
// apnatxtView.text=@"Description goes here";
apnatxtView.text=nil;
return YES;
}
}