我想要一个特定的部分indexPath
但是这段代码只给我第0部分indexPath
,因为InSection
我设置了0。
如果有多个部分,那么我如何获得indexPath
?
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[sender tag] inSection:0];
帮助我。
答案 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);
}