Iphone uitableview不使用键盘调整大小

Iphone uitableview不使用键盘调整大小,iphone,uitableview,Iphone,Uitableview,我已经创建了一个视图控制器。 设置具有一组包含文本标签的自定义单元格的tableview。当键盘打开时,tableview的框架不会自动调整大小。界面生成器中是否有我缺少的复选框或其他内容 我应该检查哪些设置?在视图控制器上添加以下键盘通知事件: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification

我已经创建了一个视图控制器。 设置具有一组包含文本标签的自定义单元格的tableview。当键盘打开时,tableview的框架不会自动调整大小。界面生成器中是否有我缺少的复选框或其他内容


我应该检查哪些设置?

在视图控制器上添加以下键盘通知事件:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
并根据键盘通知调整tableView框架的大小:

- (void)keyboardDidShow:(NSNotification *)notification
{
    NSDictionary *userInfo = [notification userInfo];
    CGSize size = [[userInfo objectForKey: UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
    CGRect frame = CGRectMake(self.tableView.frame.origin.x, 
                              self.tableView.frame.origin.y, 
                              self.tableView.frame.size.width, 
                              self.tableView.frame.size.height - size.height);
    self.tableView.frame = frame;
}

- (void)keyboardWillHide:(NSNotification *)notification
{
    NSDictionary *userInfo = [notification userInfo];
    CGSize size = [[userInfo objectForKey: UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
    self.tableView.frame = CGRectMake(self.tableView.frame.origin.x, 
                                      self.tableView.frame.origin.y, 
                                      self.tableView.frame.size.width, 
                                      self.tableView.frame.size.height + size.height);
}
如果要向上滚动tapp单元格,请在
textfielddebeginediting:
method中进行以下更改:

- (void) textFieldDidBeginEditing:(UITextField *)textField {
    UITableViewCell *cell = (UITableViewCell*) [[textField superview] superview];
    [self.tableView scrollToRowAtIndexPath:[tView indexPathForCell:cell] atScrollPosition:UITableViewScrollPositionTop animated:YES];
} 

如果您使用的是
UIViewController
,则必须在键盘出现时编写调整大小的代码。您可以处理
UIKeyboardWillShowNotification、UIKeyboardDidShowNotification、UIKeyboardWillHideNotification、UIKeyboardDidenotification
以适当调整表视图的大小。

是UIViewController还是UITableViewController?正如您所知,UITableViewController的tableView不会调整大小,所以即使您使用UIViewController,您也必须在键盘出现时编写调整大小的代码。如果是这样,我将很快对其进行更改,看看会发生什么。你说得对。我用的是UIViewController,就是这样!将其作为答案发布,我会将其标记为正确。您可以处理UIKeyboardWillShowNotification、UIKeyboardDidShowNotification、UIKeyboardWillHideNotification、UIKeyboardDidenotification以适当调整表视图的大小。我使用了UITableViewController,它现在工作正常…@matt的答案是正确的。当键盘出现时,您不应该更改tableView的框架。此代码对我来说不太适用。首先,“keyboardWillHide”功能仍然认为我的屏幕键盘高352像素,而不是0像素。其次,在横向iPad应用程序中,键盘的“高度”实际上存储在“size.width”而不是“size.height”值中。通知方法应为:[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillHide:)name:UIKeyboardWillHideNotification对象:nil];请务必将观察员移到。通常,外接程序视图将出现,而在视图中删除将消失