从集合视图中选择单元格位置
- (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];
答案 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;