Snail—UI学习之UIButton实现界面跳转及属性传值
2015-07-22 20:25
661 查看
前提是我们已经已经有了一个根UIViewController
我们新建一个SecondUIViewController 并且有一个sttr的属性 便于存储第一个界面传给第二个界面的值
在RootUiViewController中写入这些东西
接下来,到SecondUIViewController.m中
效果图如下
![](http://img.blog.csdn.net/20150722204304582?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
我们新建一个SecondUIViewController 并且有一个sttr的属性 便于存储第一个界面传给第二个界面的值
在RootUiViewController中写入这些东西
//如果有多个按钮要触发同一个操作,但是又想实现不同按钮方法将执行不同操作时,就要判断一下是哪个按钮按下了 - (void)click:(UIButton *)button{ if (button.tag == 2) { NSLog(@"button2 点我了"); }else if (button.tag == 3){ //新建一个界面 WJJSecondViewController * second = [[WJJSecondViewController alloc] init]; //给第二个界面传参数 second.attr = @"根据属性传值"; //设置反转动画 second.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; //跳转 [self presentViewController:second animated:YES completion:nil]; } }
接下来,到SecondUIViewController.m中
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor redColor]; [self createButton]; } - (void)createButton{ UIButton * btn1 = [UIButton buttonWithType:UIButtonTypeSystem]; btn1.frame = CGRectMake(50, 50, 50, 50); btn1.backgroundColor = [UIColor blackColor]; [btn1 setTitle:@"返回" forState:UIControlStateNormal]; [btn1 addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside]; //得到前面一个界面传过来的值 NSLog(@"%@",self.attr); [self.view addSubview:btn1]; } - (void)back{ //返回到前一个界面 此方法与前一个界面跳转的方法是一对,有它必有前面那个 //[self presentViewController:second animated:YES completion:nil]; //并且动画跟前一个界面转过来时得动画一样 [self dismissViewControllerAnimated:YES completion:nil]; }
效果图如下
相关文章推荐
- Snail—UI学习之得到某组件的方法
- HDU 5288 OO’s Sequence(数学啊 多校2015)
- [Leetcode]-Unique Paths
- 每天一个小知识点10(jQuerMobile总结一)
- OO’s Sequence
- 仿JD商城UI布局达到90%
- HDU5288.OO’s Sequence(多校第一题)
- 1151 - Buy or Build
- hdu 5288 OO’s Sequence(15多校第一场1001)
- Snail—UI学习之UIButton
- HDU 5288——OO’s Sequence——————【技巧题】
- Android blueZ HCI(一个):hciconfig实施和经常使用
- 数据类型转换 和 break,continue语句
- 猫猫学iOS 之微博项目实战(3)微博主框架-UIImage防止iOS7之后自动渲染_定义分类
- PHP生成百万个UID存入文件、插入数据库
- error:unknow filesystem grub rescue
- Cursor query
- soapui中文操作手册(一)----创建一个新的项目
- Android酷炫实用的开源框架(UI框架)
- js检测元素value改变