我在一个viewcontroller里面分成上下两块,
上面是一个UIView
下面是一个container view并且有另外用一个ViewControllerB去控制
我在要传值得controller加入了以下代码
protocol sendItemPriceDelegate {
func sendPrice(_ price:String)
}
并在class 下面宣告
var delegate:sendItemPriceDelegate?
然后在API回来的地方加入
self.delegate = ViewControllerB() as sendItemPriceDelegate
delegate?.sendPrice(price)
回到controllerB继承delegate并实作方法
func sendPrice(_ price: String) {
print(price)
itemPriceLabel!.text = price <===无法显示出来
}
在印出price的时候是有值的
值是有传过来的
但是要将它放在Label显示出来却一直显示不出来
请大大们解惑
感谢~~
作者:
gundam00 (傻那驾驶中)
2018-01-08 20:45:00DispatchQueue.main.async{ table.text = value }试试看
UI 更新应该是要放在main thread 没错
你指定delegate时,是指给另一个你初始化出来的 viewControllerB
一楼大大~照做了可是没用耶Orzcryinglove大~那我应该如何做才对呢?
作者:
RINPE (RIN)
2018-01-09 12:51:00这行确定有进去吗? itemPriceLabel!.text = price 设中断看一下
作者:
booray (波波)
2018-01-09 13:31:00看起来你 ViewControllerB() 这里弄出来另一个 viewcontrollerb 物件而不是显示在萤幕上那个要不要考虑改用 notification 实作?
刚刚改用了notifacation了~可是这中间会顿一下点击按钮传送通知到改变Label大约要4秒甩笨了...自己多调用了别的func,使用notifacation后就成功实现了~感谢楼上诸位大大的帮忙^^