我的应用程序中有一个文本视图,因此要在当前光标位置插入文本,我尝试了这个 工作正常的url 。
现在我遇到一个问题。
当我尝试在 viewWillAppear( ) 函数中调用 aCenterBtnClicked( ) 方法时,它显示为“2147483647 位置”( NSLog(@"%d location", myCursorPosition.location); )的当前位置。
但是当我从 viewWillAppear() 方法中隐藏 aCenterBtnCliked() 方法的函数调用时,它会将当前光标位置打印为“0 位置”( NSLog(@"%d location", myCursorPosition.location); )。
我想知道为什么在viewWillAppear函数中调用aCenterBtnCliked()方法时光标位置会发生变化
如何解决这个问题?
(void)viewWillAppear:(BOOL)animated{
//-----------------------------------
[self aCenterBtnClicked];
}
//===================================
-(void) aCenterBtnClicked{
//===================================
myCursorPosition = [self.myTextView selectedRange];
NSLog(@"%d location", myCursorPosition.location);
}