頁面?zhèn)髦?

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo; color: #008400}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo; min-height: 15.0px}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo}p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px 'PingFang SC'; color: #008400}p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo; color: #4f8187}p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo; color: #703daa}p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo; color: #3d1d81}p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo; color: #008400; min-height: 15.0px}span.s1 {font-variant-ligatures: no-common-ligatures}span.s2 {font: 13.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures}span.s3 {font-variant-ligatures: no-common-ligatures; color: #bb2ca2}span.s4 {font: 13.0px Menlo; font-variant-ligatures: no-common-ligatures}span.s5 {font: 13.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #000000}span.s6 {font-variant-ligatures: no-common-ligatures; color: #703daa}span.s7 {font-variant-ligatures: no-common-ligatures; color: #000000}span.s8 {font-variant-ligatures: no-common-ligatures; color: #4f8187}span.s9 {font-variant-ligatures: no-common-ligatures; color: #3d1d81}span.s10 {font-variant-ligatures: no-common-ligatures; color: #272ad8}span.s11 {font-variant-ligatures: no-common-ligatures; color: #d12f1b}span.s12 {font: 13.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #d12f1b}span.s13 {font-variant-ligatures: no-common-ligatures; color: #008400}span.s14 {font: 13.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400}span.s15 {font-variant-ligatures: no-common-ligatures; color: #31595d}

//
// SecondViewController.swift
// 頁面?zhèn)髦?br> //
// Created by SZT on 2016/11/4.
// Copyright ? 2016年 SZT. All rights reserved.
//

import UIKit

//從后往前傳值的協(xié)議
protocol secondProtocol{
//需要傳什么類型的參數(shù),參數(shù)列表就寫什么
func translateString(str:String)

}

class SecondViewController: UIViewController {
//定義labelStr屬性,負責(zé)接收前一個頁面?zhèn)鬟^來的值
var labelStr:String?
var textField:UITextField?

//定義代理屬性
var delegate:secondProtocol?

override func viewDidLoad() {
    super.viewDidLoad()
    //創(chuàng)建文本框textField
    textField = UITextField(frame: CGRectMake(50, 150, 90, 40))
    textField?.borderStyle = .RoundedRect
    textField?.placeholder = "請輸入內(nèi)容"
    //將傳過來的值顯示出來
    textField?.text = labelStr
    view.addSubview(textField!)
    view.backgroundColor = UIColor.whiteColor()
    navigationItem.title = "SecondVC"
    let btn = UIButton(frame: CGRectMake(50,200,90,40))
    btn.backgroundColor = UIColor.grayColor()
    btn.setTitle("pop", forState: .Normal)
    btn.addTarget(self, action: "popToFirstVC", forControlEvents: .TouchUpInside)
    view.addSubview(btn)
    
    let modelBtn = UIButton(frame: CGRectMake(50,260,90,40))
    modelBtn.backgroundColor = UIColor.cyanColor()
    modelBtn.setTitle("模態(tài)顯示", forState: .Normal)
    modelBtn.addTarget(self, action: "modelToThird", forControlEvents: .TouchUpInside)
    view.addSubview(modelBtn)
}

func modelToThird(){
    let thirdVC = ThirdViewController()
    presentViewController(thirdVC, animated: true, completion: nil)
}

func popToFirstVC(){
    //代理傳值
    delegate?.translateString((textField?.text)!)
    navigationController?.popViewControllerAnimated(true)
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


/*
 // 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.
 }
 */

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容