ProtocolDelegate

rusli
Site Admin
文章: 212
註冊時間: 週三 7月 07, 2010 9:49 pm

ProtocolDelegate

文章rusli » 週六 12月 05, 2015 6:06 pm

ProtocolDelegate.zip
(29.28 KiB) 已下載 16 次


代碼: 選擇全部

import UIKit
protocol CallBackProtocolDelegate {
    func Sent(value: String)
}


代碼: 選擇全部

class Page1ViewController: UIViewController, CallBackProtocolDelegate {

    @IBOutlet weak var callPage2Btn: UIButton!
   
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    func Sent(value: String)
    {
        print(value)
    }
   
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
   
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
       
        if let identifier = segue.identifier
        {
            switch identifier
            {
            case "showPage2":
                let controller = segue.destinationViewController as! Page2ViewController
                controller.delegate = self
            default: break
            }
        }
    }
}


代碼: 選擇全部

class Page2ViewController: UIViewController {
   
    var delegate: CallBackProtocolDelegate?
   
    @IBOutlet weak var textValue: UITextField!
   
    @IBAction func sentPage1Action(sender: AnyObject)
    {
        delegate?.Sent(textValue.text!)
    }
   
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }
   
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}



回到「Swift」

誰在線上

正在瀏覽這個版面的使用者:沒有註冊會員 和 1 位訪客