사용자가 textView에서 항목을 클릭하면 커서가 linebreak
으로 변경되지만 변경하면 selectionRange
은 항상 실패합니다. 그 이유는 알지만, selectedRange
을 func: textViewDidChangeSelection:(UITextView*)textView
으로 변경해야합니다.UITextView change selectRange always crash
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 ** is always failed"또는 selectedRange ..입니다. – vaibhav
명확하게 설명 할 질문을 편집하십시오. –