从UIView中pushViewController一个新的viewcontroller的方法

第一种方法

从uiview中获取到他所在父视图控制器viewcontroller,用父视图控制器执行pushviewcontroller方法

    id object = [self nextResponder];
    while (![object isKindOfClass:[UIViewController class]] && object != nil) {
        object = [object nextResponder];
    }
    UIViewController *superController = (UIViewController*)object;
 
    OperationViewController *OpsViewController = [[OperationViewController alloc]init];
    
    [superController.navigationController pushViewController:OpsViewController animated:YES];

第二种方法

使用block回调

1.在UIView的.h文件中定义一个bock属性:@property (nonatomic, copy)void(^pushVCblock)();
2.在UIView的.m文件的要push操作的方法中执行block:self.pushVCblock()
3.在这个view所在的controller中展开block:

__block typeof(self) weakSelf = self;//block防止循环引用

_searchDefultView.MoreSearchblock = ^{
        OperationViewController *OpsViewController = [[OperationViewController alloc]init];
        [weakSelf.navigationController pushViewController:Mycontroller animated:YES];
    };

你可能感兴趣的:(从UIView中pushViewController一个新的viewcontroller的方法)