iOS项目开发实战(Swift)—View之间传递数据
来源:互联网 发布:淘宝网免费开店 编辑:程序博客网 时间:2024/06/04 18:11
1.ViewController.Swift
- import UIKit
- class ViewController: UIViewController {
- let textField = UITextField()
- let button = UIButton()
- override func viewDidLoad() {
- super.viewDidLoad()
- textField.frame = CGRectMake(20, 20, 100, 50)
- textField.textColor = UIColor.blueColor()
- textField.placeholder = "Input:"
- button.frame = CGRectMake(0, 55, 50, 50)
- button.backgroundColor = UIColor.blackColor()
- button.setTitle("UP", forState: UIControlState.Normal)
- button.addTarget(self, action: "jump", forControlEvents: UIControlEvents.TouchUpInside)
- self.view.addSubview(button)
- self.view.addSubview(textField)
- }
- func jump(){
- let viewController = NextViewController()
- //传递数据
- viewController.labelContent = textField.text!
- presentViewController(viewController, animated: true, completion: nil)
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- }
2.NextViewController.swift
- import UIKit
- class NextViewController: UIViewController {
- var label = UILabel()
- var labelContent = " "
- var button = UIButton()
- override func viewDidLoad() {
- super.viewDidLoad()
- self.view.backgroundColor = UIColor.whiteColor()
- label.frame = CGRectMake(20, 20, 100, 50)
- label.textColor = UIColor.blackColor()
- label.text = labelContent
- self.view.addSubview(label)
- button.frame = CGRectMake(20, 80, 50, 50)
- button.setTitle("Back", forState: UIControlState.Normal)
- button.backgroundColor = UIColor.blackColor()
- button.addTarget(self, action: "backPressed:", forControlEvents: UIControlEvents.TouchUpInside)
- self.view.addSubview(button)
- // Do any additional setup after loading the view.
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- func backPressed(sender: AnyObject){
- //返回上一个视图
- dismissViewControllerAnimated(true, completion: nil)
- }
- /*
- // MARK: - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
- // Get the new view controller using segue.destinationViewController.
- // Pass the selected object to the new view controller.
- }
- */
- }
阅读全文
0 0
- iOS项目开发实战(Swift)—View之间传递数据
- iOS项目开发实战(Swift)—View之间传递数据
- iOS的View之间的数据传递
- iOS的View之间的数据传递
- iOS的View之间的数据传递
- iOS的View之间的数据传递
- iOS的View之间的数据传递
- IOS VIEW之间数据传递的方法
- iOS的View之间的数据传递
- iOS的View之间的数据传递
- iOS项目开发实战(Swift)—项目目录和结构
- iOS项目开发实战(Swift)—简单浏览器
- iOS项目开发实战(Swift)—查询天气小应用
- iOS项目开发实战(Swift)—Button和Alert学习
- iOS项目开发实战(Swift)—初探TableView
- iOS项目开发实战(Swift)—代理的使用
- iOS 应用view之间数据传递的方式
- Swift开发iOS项目实战视频教程(十六)---围住神经猫1(single view 与 empty application模板)
- XMPPManager 解析
- shell基础入门(一)
- vue常见问题解决办法(一)|vue.js报错“Do not use 'new' for side effects“(main.js里)解决办法
- Libevent的使用
- Java开发中的23种设计模式详解----访问者模式(Visitor)
- iOS项目开发实战(Swift)—View之间传递数据
- java 超时任务---设定任务执行时长,超时停止
- HNCU1325: 算法2-3~2-6:Big Bang(静态链表)
- vue.js路由vue-router(一)——简单路由基础
- weblogic11g的安装配置
- Javascript的封装库
- Xcode 工程文件“.xcodeproj”文件夹解析
- Android进程优先级
- CI持续集成系统环境---部署gerrit环境完整记录