swift的protocol

前端之家收集整理的这篇文章主要介绍了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

}

猜你在找的Swift相关文章