当前行委托UITableView隐藏行

时间:2014-01-13 11:01:02

标签: ios objective-c xcode uitableview

我有一段代码,其中委托了UITableView。我希望用于编辑表中行的功能。当用户单击某行时,将打开shouldChangeTextInRange。

通过以下代码,我可以控制行的编辑。这很好。

textView.text = ((ANFreeEditCell*)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:[self.tableView indexPathForCell:cell].row inSection:0]]).getTekst;

也可以编辑表格中的一个底行。在这种情况下,键盘窗口位于表格的顶部,self.tableView indexPathForCell:cell].row返回零行(0)。

永远不会调用didSelectRowAtIndexPath。

如何访问这些行?

2 个答案:

答案 0 :(得分:1)

您可以设置表格的内容偏移量,使其以编程方式滚动。注册UIKeyboardDidShowNotification并滚动表格,以便正在编辑的行不会隐藏在键盘后面。我没有测试过,但我相信它应该可行

希望这会有所帮助。

考虑到Simon的建议

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didShowKeyBoard:) name:UIKeyboardDidShowNotification object:nil];

-(void)didShowKeyBoard:(NSNotification *)notif
{
    float offset = //Value through which you need the tableview to scroll
    CGRect cellRect = [self.tableView rectForRowAtIndexPath:_editCellIndexPath];
    CGPoint scrollPoint = CGPointMake(0.0, cellRect.origin.y - (offset-self.tableView.contentOffset.y));
    [self.tableView setContentOffset:scrollPoint animated:YES];
}

答案 1 :(得分:0)

您需要在方法中添加observerkeyboard notification,然后在viewDidLoad内加上NSNotification,其中keyboard会在[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:self.view.window]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:self.view.window]; 隐藏时调用显示: -

tableview

现在实现键盘隐藏和显示的两种方法,然后只需设置- (void)keyboardWillHide:(NSNotification *)notification { //return it to its original position [self.tableView setFrame:CGRectMake(3, 403, 695, 353)]; } - (void)keyboardWillShow:(NSNotification *)notification { //Or where ever you want the tableView to go [self.tableView setFrame:CGRectMake(3, 65, 695, 353)]; } 的框架取决于您的视图大小。例如。

{{1}}