在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
SecondViewController的代码import UIKit //定义闭包类型(特定的函数类型函数类型) typealias InputClosureType = (String) -> Void protocol SecondViewControllerDelegate: NSObjectProtocol{ func fetchBackString(str: String) } class SecondViewController: UIViewController { @IBOutlet weak var inputTextField: UITextField! //接收上个页面传过来的闭包块 var backClosure: InputClosureType? weak var delegate: SecondViewControllerDelegate? override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } @IBAction func tapBackButton(sender: UIButton) { if self.backClosure != nil { if let tempString = self.inputTextField.text { self.backClosure!(tempString) } } self.navigationController?.popViewControllerAnimated(true) } @IBAction func delegateBackMethod(sender: UIButton) { if self.delegate != nil { if let tempString = self.inputTextField.text { delegate!.fetchBackString("代理返回数据:\(tempString)") } } self.navigationController?.popViewControllerAnimated(true) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } } 效果视图:
|
请发表评论