【问题标题】:UITableView move up when keyboard is active键盘处于活动状态时 UITableView 向上移动
【发布时间】: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


【解决方案1】:

如果可能,请使用UITableViewController,键盘会自动处理。

否则,将表格视图的contentInset属性调整为outlined by Apple

【讨论】:

    猜你喜欢
    • 2021-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多