swift的protocol
新建一个Protocol.swift文件 里面的内容 为
import Foundation protocol ChangeTextDelegate{ func changeLableValue(newString:String)
} class OtherVC: UIViewController { var delegate : ChangeTextDelegate? override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. @IBAction func otherButtonClick(sender: UIButton) {
delegate!.changeLableValue("这是第二个") self.dismissViewControllerAnimated(true) { () -> Void in
} class ViewController: UIViewController,ChangeTextDelegate { func changeLableValue(newString: String) { lable.text=newString @IBOutlet weak var lable: UILabel! @IBOutlet weak var btnClick: UIButton! @IBAction func buttonClick(sender: UIButton) { let storyBoard = UIStoryboard(name: "Main",bundle: nil) let otherVc :OtherVC = storyBoard.instantiateViewControllerWithIdentifier("OtherVC") as! OtherVC
otherVc.delegate=self self.presentViewController(otherVc,animated: true) { () -> Void in } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |