美文网首页
UICollectionView的头部添加按钮后,无法使用pus

UICollectionView的头部添加按钮后,无法使用pus

作者: xiaomayi2012 | 来源:发表于2016-10-29 22:39 被阅读31次

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;
}```

相关文章

网友评论

      本文标题:UICollectionView的头部添加按钮后,无法使用pus

      本文链接:https://www.haomeiwen.com/subject/kmbyuttx.html