您的位置:首页 > 其它

在tableView或者collectionView里如何获得被点击的cell的下标位置

2016-01-04 13:37 381 查看
/**只能用在UITableView里的方法
* indexPathForSelectedRow可以传递被选中的row,此方法可借鉴。
*/
//NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];


/**只能用在collectionView里的方法
* 可以获取collectionView当前所有被选中的cell的下标,但是只能获取到第一个位置,需要传入参数来使用。
*/
//NSIndexPath *firstIndexPath = [[self.collectionView indexPathsForVisibleItems] firstObject];


/**用在collectionView里的方法
* 将collectionView在控制器view的中心点转化成collectionView上的坐标,获取collectionView被选中的cell
*/
//CGPoint pInView = [self.view convertPoint:self.collectionView.center toView:self.collectionView];
//NSIndexPath *indexPathNow = [self.collectionView indexPathForItemAtPoint:pInView];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: