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

时间:2017-03-03 06:51:49

标签: ios objective-c uitableview nsindexpath

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

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

帮助我。

2 个答案:

答案 0 :(得分:0)

tag上的sender属性正在返回其默认值 确保在tag创建期间适当设置sender,它应设置为:

myView.tag = indexPath

现在,sender会在执行以下操作时返回正确的indexPath值:

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

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

答案 1 :(得分:0)

如果您点击按钮,则以下代码非常有用

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

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

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