頁面?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: #703daa}p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo; color: #3d1d81}p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo; color: #4f8187}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-variant-ligatures: no-common-ligatures; color: #703daa}span.s6 {font-variant-ligatures: no-common-ligatures; color: #3d1d81}span.s7 {font-variant-ligatures: no-common-ligatures; color: #4f8187}span.s8 {font-variant-ligatures: no-common-ligatures; color: #272ad8}span.s9 {font-variant-ligatures: no-common-ligatures; color: #d12f1b}span.s10 {font: 13.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #d12f1b}span.s11 {font-variant-ligatures: no-common-ligatures; color: #000000}span.s12 {font-variant-ligatures: no-common-ligatures; color: #008400}span.s13 {font: 13.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures; color: #008400}

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

import UIKit

/*
界面通信:界面?zhèn)髦?br> (1)從前往后傳
-- 屬性傳值
(2)從后往前傳
-- <1>代理傳值,<2>closure(閉包)傳值
*/
class ViewController: UIViewController {
var label:UILabel?

override func viewDidLoad() {
    super.viewDidLoad()
    
    label = UILabel(frame: CGRectMake(50, 150, 90, 30))
    label?.text = "海賊王"
    view.addSubview(label!)
    navigationItem.title = "FirstVC"
    let btn = UIButton(frame: CGRectMake(50,200,90,40))
    btn.backgroundColor = UIColor.grayColor()
    btn.setTitle("push", forState: .Normal)
    btn.addTarget(self, action: "pushToSecondVC", forControlEvents: .TouchUpInside)
    view.addSubview(btn)
    
    
}

func pushToSecondVC(){
    
    let secondVC = SecondViewController()
    //將當前的控制器設(shè)置為secondVC的代理
    secondVC.delegate = self
    //實例化
    //傳值
    secondVC.labelStr = label?.text
    navigationController?.pushViewController(secondVC, animated: true)
}

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

}
//設(shè)置了代理就一定要遵循協(xié)議
extension ViewController:secondProtocol{
func translateString(str: String) {
label?.text = str
}
}

最后編輯于
?著作權(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)容