在UIView页面执行pushViewController操作
2016-01-08 14:57
369 查看
由于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];
这里介绍两种解决方案,第一种是常用的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];
相关文章推荐
- iOS Newbie - Xcode 7 & iOS 9 UITextField & UITextView
- UEditor图片路径-从后台传递参数
- 自定义UISlider的样式和滑块
- 01-08 UICollectionView 例子
- UISlider自定义高度
- UIAlertController中添加DatePicker
- It is indirectly referenced from required class file ... could not find class......
- easyUI tree以及tab的创建以及应用
- bluedroid 代码框架
- UITableView使用小结(滚动到顶部、获取cell、cell选中状态、刷新cell或者section)
- UVa 12100 - Printer Queue【队列和优先队列】
- Android 更新UI的两种方法——handler和runOnUiThread()
- Android Build类
- 【LeetCode】Repeated DNA Sequences 解题报告
- Request与Response常用方法总结
- Android Contacts (一)ContentResolver query 参数详解
- UIPickerView组件的使用之——省市联动
- Map对value进行排序
- org.hibernate.exception.JDBCConnectionException: could not execute query
- apktool,dex2jar,jd-gui简单使用与实战