2016-03-28 28 views
-1

正在逐渐从集合视图选择的小区位置的iOS从NSIndexpath得到NSInteger的

- (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 = {长度= 2,路径= 0 - 1}

由此我只需要路径的第一个值..我怎么能得到它?

我可以使用此代码得到最后的价值..

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

回答

1

这是很容易:)

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

这是我工作的回答让小区索引按钮..

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

    NSInteger *rowIndex = tappedIP.row; 
+0

好工作兄弟,做得很好 –