ユーザーがtextViewで項目をクリックすると、カーソルをlinebreak
に変更しますが、変更すると常にselectionRange
は失敗します。 私はその理由を知っていますが、selectedRange
をfunc: textViewDidChangeSelection:(UITextView*)textView
に変更する必要がありますUITextView change selectRange alwaysクラッシュ
selectedRangeを変更するにはどうすればよいですか?ここ
はコードの私の下手な英語について申し訳ありません
-(void)textViewDidChangeSelection:(UITextView *)textView
// paragLocations: it contain all "\n" locations
NSArray* paragLocations = [self ParagraphLocationsWithText:textView Pattern:translatePragraphLinebreak];
// location :According to user selection,The nearest "\n" location
NSUInteger nearestLocation = [self ClickParagraphEndBreakLoctionWithSelectLocation:textView.selectedRange.location withParagLocations:paragLocations];
//Then
//1. here I change the textView.selectedRange
textView.selectedRange = NSMakeRange(nearestLocation, 0);
//2. here I change the cursorPosition
CGFloat cursorPosition = [self caretRectForPosition:textView.selectedTextRange.start].origin.y;
[textView setContentOffset:CGPointMake(0, cursorPosition) animated:YES];
// but In step 1 ,It changed textView.selectedRange,So this func will do it again,and then again,until the nearestLocation became the paragLocations.lastObject.
/*
so the question is how to break this Infinite loop ?
should I change selectedRange In this func?
I want to changed the selectedRange base on User select In textview
*/
です。
"change ** selectionRange **は常に失敗"またはselectedRange ..ですか? – vaibhav
明確に説明するための質問を編集する –