iOS get NSInteger from NSIndexpath



Am正在从集合视图中获取所选单元格位置

- (void)buttonPressed:(id)sender
{
    NSLog(@"button clicked");

  //  CGPoint buttonPosition = [sender convertPoint:CGPointZero
   //                                        toView: GlossaryCollView];
    NSIndexPath *centerCellIndexPath =
    [self.GlossaryCollView indexPathForItemAtPoint:
     [self.view convertPoint:[self.view center] toView:self.GlossaryCollView]];

    NSLog(@"cell index path :%@",centerCellIndexPath);


}

它给出的值nslog={length=2,path=0-1}

由此,我只需要路径优先值。。我怎样才能拿到它??

我可以使用此代码获取最后一个值。。

NSUInteger lastIndex = [centerCellIndexPath indexAtPosition:[centerCellIndexPath length] - 1];

这很容易:)

NSInteger row = centerCellIndexPath.row;
NSInteger section = centerCellIndexPath.section;

以下是我获取按钮单元格索引的工作答案。。

    CGPoint buttonPosition = [sender convertPoint:CGPointZero
                                           toView: self.GlossaryCollView];
    NSIndexPath *tappedIP = [self.GlossaryCollView indexPathForItemAtPoint:buttonPosition];
  NSInteger *rowIndex = tappedIP.row;

最新更新