简体   繁体   English

iOS从NSIndexpath获取NSInteger

[英]iOS get NSInteger from NSIndexpath

Am getting selected cell position from collection view 我正在从集合视图中获取选定的单元格位置

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




}

It gives the value nslog = {length = 2, path = 0 - 1} 给出值nslog = {length = 2,path = 0-1}

From this i need only the path first value.. How can i get it?? 从这,我只需要路径第一个值。如何获得它?

I can get last value using this code.. 我可以使用此代码获得最后的值。

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

It's pretty easy :) 这很容易:)

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

Here is my working answer to get the cell index for the button.. 这是我的工作答案,以获得按钮的单元格索引。

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

  NSInteger *rowIndex = tappedIP.row;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM