获取具有多个部分的行和部分的索引?

Get indexes of row and section with multiple sections?

我想要一个特定的部分 indexPath 但这段代码只给我部分 0 indexPath 因为 InSection 我设置了 0。 如果有多个部分,那么我如何获得 indexPath

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[sender tag] inSection:0];

帮我解决这个问题。

sender 上的 tag 属性是 return 默认值。
确保在 sender 创建期间正确设置 tag,它应该设置为:

myView.tag = indexPath

现在,sender 将 return 正确的 indexPath 值同时执行:

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[sender tag] inSection:0];

只需 确保 标签设置正确(我猜是在 cellForRowAtIndexpath:) 中检索正确的索引。

如果您点击按钮,下面的代码很有用

-(IBAction)btnClicked:(id)sender
{
    CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:tableviewName];

    NSIndexPath *indexPath = [self.accountTablView indexPathForRowAtPoint:buttonPosition];

    NSLog(@"section index-----%ld",(long)indexPath.section);
}