在 UICollectionView 选择上选择 UITableView [英] Select the UITableView on UICollectionView selection

查看:32
本文介绍了在 UICollectionView 选择上选择 UITableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 UITableViewCell 中有一个 UICollectionView.当我选择 tableView 行时,我不希望 UICollectionViewdidSelectItemAtIndexPath: 方法被调用.相反,我想要调用 UITableViewdidSelectRowAtIndexPath: 方法.我如何在 didSelectItemAtIndexPath: 中调用 didSelectRowAtIndexPath:?

I have a UICollectionView inside UITableViewCell. When I select the a tableView row, I do not want the didSelectItemAtIndexPath: method of UICollectionView to get called. Instead I want didSelectRowAtIndexPath: method of UITableView to get called. How would I call didSelectRowAtIndexPath: in didSelectItemAtIndexPath:?

推荐答案

设置 collectionView.allowsSelection = NO 以禁用选择.

OR 在 didSelectItemAtIndexPath 方法中,获取 UITableViewCell 并调用具有 UITableView 的表视图的委托:

OR in the didSelectItemAtIndexPath method, grab the UITableViewCell and call the delegate which is the table view that has UITableView:

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{

    UITableViewCell *parentCell = collectionView.superview;
    [parentCell.delegate collectionViewDidSelectedAtCell:parentCell];
}
// IN your view controller that has the table view

- (void)collectionViewDidSelectedAtCell:(UITableViewCell *)cell{
     NSIndexPath *index = [self.tableView indexPathForCell:cell];
     [self tableView:self.tableView didSelectRowAtIndexPath:index];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

}

这篇关于在 UICollectionView 选择上选择 UITableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆