swift的protocol

swift的protocol,第1张

概述新建一个Protocol.swift文件 里面的内容 为  import Foundation protocol ChangeTextDelegate{     func changeLableValue(newString:String)      } class OtherVC: UIViewController {          var delegate : ChangeTextDele 新建一个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的protocol全部内容,希望文章能够帮你解决swift的protocol所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1081239.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存