由于UIView没有navigationController属性,所以不能直接push操作
这里介绍两种解决方案,第一种是常用的block:
1.在UIView的.h文件中定义一个bock属性:@property (nonatomic, copy)void(^MoreSearchblock)();
2.在UIView的.m文件的要push操作的方法中执行block:self.MoreSearchblock();
3.在这个view所在的controller中展开block:
__block typeof(self) weakSelf = self;//block防止循环引用
_searchDefultView.MoreSearchblock = ^{
/**
* 这里声明所要push的页面(Mycontroller)
*/
[weakSelf.navigationController pushViewController:Mycontroller animated:YES];
};
第二种方法是直接在UIView中找到他所在的父视图控制器,通过父视图来执行push操作:
id object = [self nextResponder];
while (![object isKindOfClass:[UIViewController class]] && object != nil) {
object = [object nextResponder];
}
UIViewController *superController = (UIViewController*)object;
/**
* 这里声明所要push的页面(Mycontroller)
*/
[superController.navigationController pushViewController:Mycontroller animated:YES];