ios - UICollectionView的头部无法使用pushViewController跳转,如何解决?

查看:121
本文介绍了ios - UICollectionView的头部无法使用pushViewController跳转,如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

UICollectionView的头部中添加了一个按钮,想通过点击按钮跳转到另一个控制器,但是在UICollectionView的头部中无法使用[self.navigationController pushViewController:p animated:YES]这个方法跳转,有什么好解决方法吗??求教谢谢~!

解决方案

把下面的代码当做category放到你的项目中。

在view 里面,可以通过,[self.viewController.navigationController pushViewController:p animated:YES]进行跳转。

//获取某个view所在的控制器
- (UIViewController *)viewController {
  UIViewController *viewController = nil;
  UIResponder *next = self.nextResponder;
  while (next) {
    if ([next isKindOfClass:[UIViewController class]]) {
      viewController = (UIViewController *)next;
      break;
    }
    next = next.nextResponder;
  }
  return viewController;
}

这篇关于ios - UICollectionView的头部无法使用pushViewController跳转,如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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