Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 点击UITableViewcell的下一步按钮_Objective C_Uitableview_Iterator - Fatal编程技术网

Objective c 点击UITableViewcell的下一步按钮

Objective c 点击UITableViewcell的下一步按钮,objective-c,uitableview,iterator,Objective C,Uitableview,Iterator,我想知道如何才能实现以下目标: 创建“下一步”按钮,点击该按钮后,将选择下一个UITableview行 因为一张图片抵得上千言万语,所以我添加了一个截图 正如您在下面看到的,我添加了一个工具栏,如果我按下右键,它必须选择下一行。关于如何实现这一点的任何建议(我假设使用某种迭代器) 另外,我希望行的行为也像它被触摸过一样(这样我就可以在它后面放置一个动作)也许你的问题有些复杂,但我不知道,但是你可以简单地在代码中跟踪所选行,当你从工具栏按钮获得事件时,增加所选行索引并使用: -selectRow

我想知道如何才能实现以下目标:
创建“下一步”按钮,点击该按钮后,将选择下一个UITableview行

因为一张图片抵得上千言万语,所以我添加了一个截图

正如您在下面看到的,我添加了一个工具栏,如果我按下右键,它必须选择下一行。关于如何实现这一点的任何建议(我假设使用某种迭代器)


另外,我希望行的行为也像它被触摸过一样(这样我就可以在它后面放置一个动作)

也许你的问题有些复杂,但我不知道,但是你可以简单地在代码中跟踪所选行,当你从工具栏按钮获得事件时,增加所选行索引并使用:

-selectRowAtIndexPath:animated:scrollPosition:

在您的表上选择行?

类似这样的操作应该可以:

- (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
}

超级thnx人..不幸的是,我忘了添加一部分,该行需要像已单击一样进行操作;)。。这段代码非常完美,但很不幸,它的行为不像触摸(例如,如果你触摸第二行,它会得到该单元格后面的动作)。。但无论如何,非常感谢是的,这是预期的行为。从selectRowAtIndexPath:animated:scrollPosition的文档中可以看到:“调用此方法不会导致代理收到tableView:willSelectRowAtIndexPath:或tableView:didSelectRowAtIndexPath:消息,也不会向观察者发送UITableViewSelectionDidChangeNotification通知。”换句话说,你必须自己调用这些方法。我已经编辑了上面的代码这样做。好的超级thnx。。。但我做了一些调整..我所需要的只是这个[self tableview:[self tableview]didSelectRowAtIndexPath:selectedRow];但是我再次建议你把上面的代码放在UITableView类别中。。但我忘了提到我希望它表现得像被选中、被触摸一样;)thnx对于回复,如果您正在实现-tableView:didSelectCellAtIndexPath:按照正常方式,为什么不直接调用该方法呢?您正在为该行计算一个
indepath
,因此只需调用selection delegate方法即可。对不起,它是
-tableView:didSelectRowAtIndexPath:
不是didSelectCellAtIndexPath。我应该仔细检查一下,抱歉。好家伙,我已经把这个添加到底部了,效果很好。。[self tableview:[self tableview]didSelectRowAtIndexPath:selectedRow];thnx
- (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];
}