search

Home  >  Q&A  >  body text

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

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

PHP中文网PHP中文网2828 days ago765

reply all(2)I'll reply

  • ringa_lee

    ringa_lee2017-04-18 09:42:17

    Put the following code into your project as a category.

    In the view, you can jump through [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;
    }

    reply
    0
  • 高洛峰

    高洛峰2017-04-18 09:42:17

    I tested it and it can be jumped. Is your navigation valuable? Or is it another problem? Can you make the problem more specific? It would be best if you could look at the code.

    reply
    0
  • Cancelreply