【问题标题】:Detecting an inserted cell and then having it becomeFirstResponder检测插入的单元格,然后让它成为FirstResponder
【发布时间】:2013-04-10 12:44:29
【问题描述】:

对于我的自定义单元格,举个简单的例子,我只有一个UITextField,有没有办法让insertRowsAtIndexPaths 刚刚插入的单元格becomeFirstResponder

我需要一种方法来检测这一点,以便在插入后和插入动画结束时成为第一响应者。

有什么想法,甚至接近吗?

谢谢

【问题讨论】:

  • 你会一直插入一行吗?或者是否可以插入多行?那么你希望哪一个作为第一响应者?
  • 一次总是一行。

标签: ios objective-c uitableview


【解决方案1】:

像这样的东西??

- (void) insertRows
{
    .
    .
    .

    [tableView beginUpdates];
    [tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationRight];
    [tableView endUpdates];

    NSIndexPath p = [indexPaths lastObject];

    MyCustomCell *cell = [cellForRowAtIndexPath:p];
    [cell.textField becomeFirstResponder];
}

【讨论】:

  • 如果我还在 cellForRowAtIndexPath 上使用单元出队,这将如何工作?在执行 insertRowsAtIndexPaths 之后,将调用 cellForRowAtIndexPath。是否有回调可以用来检测动画何时结束。
  • 另外,为什么需要 [tableView beginUpdates]/endUpdates?没有它,动画也能正常工作。
  • 如果它在没有 begin/endUpdates 的情况下工作,那很好.. 但是您必须将 tableView 滚动到最近插入的行,以便它可见 [tableView scrollToRowAtIndexPath:p atScrollPosition:UITableViewScrollPositionTop animated:YES]; MyCustomCell *cell = [cellForRowAtIndexPath:p]; [cell.textField becomeFirstResponder];
猜你喜欢
  • 2016-11-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-15
  • 1970-01-01
  • 2011-08-30
  • 1970-01-01
相关资源
最近更新 更多