iOS从NSIndexpath获取NSInteger

时间:2016-03-28 06:55:01

标签: ios objective-c

从集合视图中选择单元格位置

- (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];

2 个答案:

答案 0 :(得分:1)

这很简单:)

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

答案 1 :(得分:1)

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

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

  NSInteger *rowIndex = tappedIP.row;