标签:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
import UIKit class ViewController : UIViewController , EditViewControllerDelegate { @IBOutlet weak var label: UILabel ! 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. } //页面跳转时 override func prepareForSegue(segue: UIStoryboardSegue , sender: AnyObject ?) { if segue.identifier == "EditView" { //通过seque的标识获得跳转目标 let controller = segue.destinationViewController as EditViewController //设置代理 controller.delegate = self //将值传递给新页面 controller.oldInfo = label.text } } func editInfo(controller: EditViewController , newInfo: String ){ label.text = newInfo; //关闭编辑页面 controller.presentingViewController!.dismissViewControllerAnimated( true , completion: nil ) } func editInfoDidCancer(controller: EditViewController ){ //关闭编辑页面 controller.presentingViewController!.dismissViewControllerAnimated( true , completion: nil ) } } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
import UIKit class EditViewController : UIViewController { @IBOutlet weak var textField: UITextField ! var delegate: EditViewControllerDelegate ? var oldInfo: String ? override func viewDidLoad() { super .viewDidLoad() // Do any additional setup after loading the view. if oldInfo != nil { textField.text = oldInfo } } override func didReceiveMemoryWarning() { super .didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } @IBAction func done(sender: AnyObject ) { delegate?.editInfo( self , newInfo: textField.text) } @IBAction func cancel(sender: AnyObject ) { delegate?.editInfoDidCancer( self ) } } |
1
2
3
4
|
protocol EditViewControllerDelegate { func editInfo(controller: EditViewController , newInfo: String ) func editInfoDidCancer(controller: EditViewController ) } |
标签:
原文地址:http://www.cnblogs.com/Free-Thinker/p/4841059.html