iOS 之 跳转到新页面 2个页面间跳转和数据传递
来源:互联网 发布:小游戏制作软件 编辑:程序博客网 时间:2024/04/29 14:45
今天,介绍一下2个多个页面 界面 到跳转。首先普及一下基础知识:每个界面用storyboard来设计,然后每个界面有自己到viewcontroller。这是必须的。
一,界面跳转
ios7的storyboard模式,所有的界面都在同一个 storyboard中。我们打开主story。新加一个view controller。拖动到右边就行。
然后有2种方式添加 关联:
第一种
在第一个view controller中加一个button。点中button,control+鼠标左键(或者鼠标右键拖动)拖动到第二个view controller中。选push方式,model,custum方式都行。
然后run 就行。看看效果吧。
第二种:代码方式
选第一个view controller,右键拖动到第二个view controller中,选custom方式(其他方式都行)。然后在2个view之间 有一条线,这跳线 就是segue。选中这跳线,给他来个identifier,比如叫 secondView
然后给第二个view 关联view controller 的class
选中 view controller 再选 custom class 设置为 SecondViewController 这就是把 这个控件和一个类关联起来了。
给第一个view controller 中添加一个button,添加一个 touch up inside 事件,函数如下,具体怎么添加,看我以前到blog
- (IBAction)sender:(id)sender
{
NSLog(@"%@",@"wwww");
[selfperformSegueWithIdentifier:@"secondView"sender:self];
// [self presentModalViewController:nil animated:YES];
}
然后run 就行。点button后 就打开第二页了。
二,界面传值
在第一个storyboard的第一个view controller。m文件中,加入
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifierisEqualToString:@"secondView"])
{
id theSegue = segue.destinationViewController;
[theSeguesetValue:elementarrayforKey:@"elementarray"];
}
}
就行了。
[theSegue setValue:elementarray forKey:@"elementarray"]; 这句中的 elementarray 就是要传的变量。
在第二个view controller控制的view controller。h中
//传过来的result,变量
@property (nonatomic,strong)NSMutableArray *elementarray;
@synthesize elementarray;
-(void) viewDidLoad
{
NSLog(@"%lu", (unsignedlong)elementarray.count);
for (NSMutableDictionary *tinelementarray)
{
NSLog(@"%@", [tobjectForKey:@"name"]);
}
}
就可以接收到了。就是注意第二个view到类型 要和第一个view中变量的类型完全一致即可。
别的没了。
附上segue的图
- iOS 之 跳转到新页面 2个页面间跳转和数据传递
- js页面跳转和打开新页面
- iframe跳转到新页面
- form跳转到新页面
- 关闭整个框架页面并且跳转到新页面
- 关于frameset帧页面跳转到新页面的问题
- jquery,JavaScript,页面跳转,打开新页面,返回,跳转页面同时传递参数
- 页面跳转和数据传递
- 页面跳转和数据传递
- iOS页面跳转传递数据之block的使用
- h-ui跳转到新页面
- 跳转到新页面无法定位新元素
- IOS 页面跳转的数据传递方式
- iOS页面跳转及数据传递
- IOS 页面跳转的数据传递方式
- iOS页面跳转及数据传递
- iOS页面跳转及数据传递
- iOS页面跳转及数据传递
- Kamailio v4.1.6 发布,开源 SIP 服务器
- 详解Android中的屏幕方向
- 抽象类与接口的区别
- 自己实现popen函数
- 一个可以作为代理服务器或者转发的java类
- iOS 之 跳转到新页面 2个页面间跳转和数据传递
- 猴子吃桃
- Android 数据库框架学习之LitePal基础(一)
- 自由使用yii的验证码总结
- 算法摘记 树状数组
- 东软学习,strut2初级学习马士兵的部分截图和笔记(七)-标签学习
- 【视频】基于Android的开源平板系统构成分析
- spring-Annotation
- 基类显式继承接口,类继承基类时又继承同一接口,引发接口方法混乱(显式继承接口的弊端)