IOS 页面之间的跳转以及传值
来源:互联网 发布:如何做好淘宝客推广 编辑:程序博客网 时间:2024/05/17 05:10
一.页面之间的跳转
1.navigation页面之间的跳转
[self.navigationController pushViewController:destViewCtl animated:YES];//跳转到目的页面
[self.navigationController popViewController:sourceViewCtl animated:YES];//从目的页面返回到原来页面
[self.navigationController popToRootViewControllerAnimated:YES];//返回根控制器,就是最开始初始化navigtion时选择的根页面
2.modal形式页面跳转
[self presentViewController:newC animated: YES completion:nil];//跳转到目的页面
[ self dismissViewControllerAnimated: YES completion: nil ];//从目的页面返回到原来页面
3.使用tabBarCtl时
有时通过 [tabbarCtl addChildViewController :destViewCtl ];添加子视图,比较少用。
目前一般自定义TabBar控件,初始化时直接加载进设定好的几个子视图
4.比较极端的方法,直接修改根视图控制器
self.window.rootViewController=destViewCtl;
5.直接进行UIView的跳转
[self.view addSubview:destView];
[self.view remoFromSuperView];
[self.view bringSubviewToFront:destView]
[self.view sendSuperViewToBottom:destView];
二. 不同视图间的传值
定义A,B两个ViewCtl,实现从A向B传值
1.定义属性变量传值
在B头文件中定义属性变量 @property NSString *strValue;
在A的.m文件中引入B的头文件,在界面跳转前通过定义的B类对象实例给 strValue赋值,界面跳转后即可在B中使用
B=[[UIViewController alloc]init]; B.strValue=destValue; 跳转到B中
2.代理传值(感觉和1类似,是否有安全方面问题暂无研究)
首先定义协议
@protocol sendValueDelegate
-(void)sendValue:(NSString *)destValue;
@end
在A中引用协议头文件并定义属性变量
@property(nonatomic, retain) id<sendValueDelegate >sendDelegate;
在执行函数中调用代理函数并跳转到B
B *b=[[B alloc]init];
self.sendDelegate=b;
[self.sendDelegate sendValue:XXX];
跳转B页面
在B的头文件中加入代理头文件并引用代理
@interface B : NSObject <sendValueDelegate>
- (void) sendValue:(NSString *) destValue;
@end
在B的头文件中实现方法,并接收传过来的值
- (void) setValue:(NSString *) destValue{
NSString *str=destValue;
}
3通知传值
在A中
创建传值用的字典,里面保存键名键值
NSDictionary *sendDict=[[NSDictionary alloc]initWithObjectsAndKeys:keyName,keyValue,........,nil];
创建通知
NSNotification *sendNotific=[NSNotification notificationWithName:@"notiName" object:nil userInfo:sendDict];
发送通知
[[NSNotificationCenter defaultCenter]postNotification:sendNotific];
在B中
[[NSNotificationCenterdefaultCenter]addObserver:self selector:@selector(notificAction:)name:@"notiName"object:nil];
通知方法
- (void)notificAction:(NSNotification *)sendInfo{
NSDictionary *dict =sendInfo.userInfo;
NSString *str= 从字典中根据具体键名取出具体数据;
NSLog(@"%@",str);
- IOS 页面之间的跳转以及传值
- IOS页面之间的跳转 加精
- activity之间的跳转以及传值
- iOS app之间的跳转以及传参数
- android页面的跳转以及传值
- js实现html 页面之间的跳转传参以及返回上一页的相关知识点
- js实现html 页面之间的跳转传参以及返回上一页的相关知识点
- android开发中页面之间跳转的传值问题
- 【android开发】页面之间的跳转和传值
- react页面之间的跳转及传值
- js 页面之间的跳转、传参以及返回上一页
- js 页面之间的跳转、传参以及返回上一页
- 【代码笔记】iOS-页面之间的跳转效果
- iOS应用之间的跳转,进入指定页面
- tabhost不同选项卡之间的跳转以及传值
- Android界面跳转以及界面之间的传值
- 两个应用之间的跳转以及传值
- ios页面跳转传值
- 使用gcc生成动态链接库dll的方法
- Ubuntu上Docker安装
- 实现带样式的表单验证:用户名、密码验证
- java多线程的一个案例
- 转载一篇对php变量名的问题,很有意思,之前没注意过
- IOS 页面之间的跳转以及传值
- GDB调试器
- bjfu.oj-1470 poj-2777
- 读取并修改元素的属性:实现多标签页效果
- php redis 常用操作
- [算法]欧几里得算法——求解最大公因数
- hdu4021——N数码问题及其扩展
- make
- 安卓开发:Volley加载图片