【发布时间】:2015-08-08 12:58:34
【问题描述】:
我有 UITableView 和 UITextfields 作为 contentView 中的子视图。
它们都可以工作,但是当我选择底部的那些时,它们会被键盘覆盖,所以我希望 UITableView 向上滚动。
这是我当前的代码:
-(void)keyboardWillShow:(NSNotification*)notification {
NSValue *keyboardFrameValue = [[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey];
CGRect keyboardFrame = [[self view] convertRect:[keyboardFrameValue CGRectValue] fromView:nil];
[UIView animateWithDuration:0.3 animations:^{
[constraint setConstant:keyboardFrame.size.height];
[self.myTableView layoutIfNeeded];
}];
}
-(void)keyboardWillHide:(NSNotification *)notification {
[UIView animateWithDuration:0.3 animations:^{
[constraint setConstant:0];
[self.myTableView layoutIfNeeded];
}];
}
这样做的问题是它弄乱了数据,文本字段被添加到错误的单元格和东西中。
希望任何人都可以提供帮助。
【问题讨论】:
-
为什么不用第三方库?
-
为了什么?合适的视图?
标签: ios objective-c iphone uitableview