2016-03-28 57 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

好工作兄弟,做得很好 –