View上面调用push方法

方法一 (最简单的)

 在控制器里面创建view  的时候要给vc赋值
self.myHeaderView = [[myHeaderView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH,  self.myHeaderHeight)];
self.myHeaderView.vc = self;

myHeaderView.h 中创建使用weak
@property(nonatomic,weak)UIViewController *vc;

 myHeaderView.m 进行跳转

zhangHuInfoViewController *infoVC=[[zhangHuInfoViewController alloc]init];
[self.vc.navigationController pushViewController:infoVC animated:YES];

方法二 (获取该View所在的Viewcontroller)

//获取View所在的Viewcontroller方法
- (UIViewController *)viewController {
for (UIView* next = [self superview]; next; next = next.superview) {
    UIResponder *nextResponder = [next nextResponder];
    if ([nextResponder isKindOfClass:[UIViewController class]]) {
        return (UIViewController *)nextResponder;
    }
}
return nil;
}

//使用方法:
[[self viewController].navigationController pushViewController:[zhangHuInfoViewController new] animated:YES];

方法三(block或者代理)

你可能感兴趣的:(View上面调用push方法)