代碼: 選擇全部
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.
}
}