点击UITableViewcell的下一个按钮

时间:2009-07-27 13:47:17

标签: objective-c uitableview iterator

我想知道如何实现以下目标:
创建下一个按钮,当它被点击时,将选择下一个UITableview行。

由于图片胜过千言万语,我添加了截图。

http://img529.imageshack.us/img529/4341/picture5uuj.png

如下所示,我添加了一个工具栏,如果按下右键,则必须选择下一行。关于我如何处理这个的任何建议(我假设使用某种迭代器)。

PS。我希望这行也能像被触摸那样行动(所以我可以在它背后加一个动作)

3 个答案:

答案 0 :(得分:1)

也许你的问题有些复杂,我错过了,但你可以简单地跟踪代码中的选定行,当你从工具栏按钮中获取事件时,增加你选择的行索引并使用:

-selectRowAtIndexPath:animated:scrollPosition:
在你的桌子上

选择行?

答案 1 :(得分:1)

这样的事情可以解决问题:

- (void)selectNextRow
{
  NSIndexPath *selectedRow = [self.tableView indexPathForSelectedRow];
  NSUInteger row = selectedRow.row;
  NSUInteger section = selectedRow.section;
  ++row;
  if(row >= [self.tableView numberOfRowsInSection:selectedRow.section])
  {
    row = 0;
    ++section;
    if(section >= [self.tableView numberOfSections])
    {
      row = 0;
      section = 0;
    }
  }
  NSIndexPath *rowToSelect = [self tableView:self.tableView willSelectRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:section]];
  [self.tableView selectRowAtIndexPath:rowToSelect animated:YES scrollPosition:UITableViewScrollPositionMiddle];
  [self tableView:self.tableView didSelectRowAtIndexPath:rowToSelect];
  // also, post notifications if desired
}

答案 2 :(得分:1)

- (IBAction)btnClicked:(id)sender 
{
    NSIndexPath *selectedRow = [self.MyTableview indexPathForSelectedRow];
    int i=selectedRow.row;
    i++;

    NSIndexPath* selectedCellIndexPath= [NSIndexPath indexPathForRow:i inSection:0];
    [MyTableview selectRowAtIndexPath:selectedCellIndexPath animated:false scrollPosition:UITableViewScrollPositionMiddle];
}
相关问题