【问题标题】:How to initiate a UINavigationController push in response to a tap on a UICollectionViewCell如何启动 UINavigationController 推送以响应对 UICollectionViewCell 的点击
【发布时间】:2014-03-18 05:05:03
【问题描述】:

我正在使用UICollectionView,但是当我点击 UICollectionViewCell 时无法导航到另一个视图。

这是我的代码。

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:
    (NSIndexPath *)indexPath
{
    if (indexPath.row==0)
    {
        AboutTheBook *alarmView1 = [self.storyboard instantiateViewControllerWithIdentifier:@"AboutTheBook"];
        [self.navigationController pushViewController:alarmView1 animated:YES]; 
    }
}

【问题讨论】:

  • 你确定这个方法正在被访问,即你已经设置了 UICollectionView 的委托属性吗?
  • 这与委托无关,这是一个问题用户没有设置导航控制器,因此他们无法从 didSelect 推送视图控制器。

标签: ios xcode ios7 uicollectionview uicollectionviewcell


【解决方案1】:

确定

  1. 导航控制器嵌入到您尝试推送的 VC [或在其上面的流程中进入堆栈的 VC]
  2. AboutTheBook 是故事板中 VC 的唯一标识符
  3. 您正在点击集合视图的索引 0

【讨论】:

    【解决方案2】:

    试试这个。

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];
    AboutTheBook *alarmView1=(AboutTheBook *)[storyboard instantiateViewControllerWithIdentifier:@"AboutTheBook"];
    [self.navigationController pushViewController:alarmView1 animated:YES];
    

    【讨论】:

      猜你喜欢
      • 2013-01-29
      • 1970-01-01
      • 1970-01-01
      • 2017-10-20
      • 1970-01-01
      • 1970-01-01
      • 2022-01-15
      • 1970-01-01
      • 2012-03-14
      相关资源
      最近更新 更多