这是操作顺序的问题
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[nc addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
然后我向 UITableViewCell 添加一个文本框:
[textField addTarget:self
action:@selector(textFieldBegin:)
forControlEvents:UIControlEventEditingDidBegin];
[cell addSubview:textField];
在 textFieldBegin 中,我 scrollToRowAtIndexPath 移动到正在编辑的单元格。
在keyboardWillShow 中,我调整了tableView 的框架以允许使用键盘。
textFieldBegin在keyboardWillShow之前 被调用,所以第一次显示时没有滚动空间。
有没有一种方法可以解决这种疏忽?