表格视图在文本字段开始编辑iphone时滚动 [英] Table View scroll when text field begin editing iphone

查看:87
本文介绍了表格视图在文本字段开始编辑iphone时滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iphone应用程序中有表视图控制器。表视图有两个部分。第一部分有两行,第二部分有一行。第二部分有一个自定义表格视图单元格。

I have table view controller in iphone application. Table view has two sections. First section has two rows and second section has one row. Second section has a custom table view cell.

第二部分有一个文本字段,当文本字段开始编辑并弹出键盘时会隐藏该文本字段。我希望这个表格视图在键盘弹出时滚动。

Second section has a textfield which hides when text field begin editing and keyboard pops up. I want this table view to scroll when keyboard pops up.

我尝试了以下代码,我在不同的网站上遇到但是徒劳无功。

I tried the following code which I came across on different websites but in vain.

提前致谢。

-(void) textFieldDidBeginEditing:(UITextField *)textField {

    CGRect textFieldRect = [textField frame];
    [self.tableView scrollRectToVisible:textFieldRect animated:YES];
} 
                          atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
}

-(void) textFieldDidBeginEditing:(UITextField *)textField {

    UITableViewCell *cell = (UITableViewCell*) [[textField superview] superview];
    [self.tableView scrollToRowAtIndexPath:[tableView indexPathForCell:cell] 
                          atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
}


推荐答案

我遇到过这个问题静态Cell TVC。覆盖 viewWillAppear 并且不调用其Super时会出现问题。所以,如果你这样做,请务必致电

I have run into this on Static Cell TVC's. There is an issue when overriding viewWillAppear and NOT calling its Super. So if you are doing that, make sure to call

[super viewWillAppear:animated];

位于顶部viewWillAppear

这篇关于表格视图在文本字段开始编辑iphone时滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆