Swift3.0 代理传值,属性传值

本文介绍了一个Swift应用中如何使用代理模式来实现MapViewController与AddOrderViewController之间的地址信息传递。通过定义MapViewDelegate协议并实现selectedAddress方法,实现了从地图选择地址后的回调处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.代理传值()MapViewController传值

protocol MapViewDelegate : NSObjectProtocol

{

    func selectedAddress(mapViewController:MapViewController,address:String?)

}

weak var delegate:MapViewDelegate?

self.delegate?.selectedAddress(mapViewController: self,address: currentAddress)


2.接收值 AddOrderViewController

mapVC.delegate =self

extension AddOrderViewController:MapViewDelegate{

    func selectedAddress(mapViewController:MapViewController, address:String?) {

        guardlet path = address else { return }

        if mapViewController.view.tag ==1 {

            self.source = path

            //nOrder.sourcePlace = path

            let paths = [IndexPath(row:0, section: 0)]

            self.tableView.reloadRows(at: paths, with: .automatic)

        }else{

            self.destination = path

            //nOrder.destinationPlace = path

            let paths = [IndexPath(row:1, section: 0)]

            self.tableView.reloadRows(at: paths, with: .automatic)

        }

    }

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值