先写一个方法, 强制增加一个navigation的属性. 这样self就可以调出来navigation了

- (UINavigationController*)naviController {
    
    for (UIView* next = [self superview]; next; next = next.superview) {
        
        UIResponder* nextResponder = [next nextResponder];
        
        if ([nextResponder isKindOfClass:[UINavigationController class]]) {
            
            return (UINavigationController*)nextResponder;
        }
    }
    
    return nil;
}

 然后, 在cell的点击方法中调用这个属性, 并推出一个新的界面:

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    myViewController *vc = [[myViewController alloc]init];
    
    [[self naviController] presentViewController:vc animated:YES completion:nil];
    
}

 

相关文章:

  • 2021-11-04
  • 2022-12-23
  • 2021-07-09
  • 2021-12-09
  • 2022-02-21
  • 2022-12-23
  • 2022-12-23
  • 2021-06-16
猜你喜欢
  • 2021-06-21
  • 2021-11-06
  • 2021-12-06
  • 2022-12-23
  • 2022-12-23
  • 2022-02-08
  • 2022-12-23
相关资源
相似解决方案