看板 MacDev 關於我們 聯絡資訊
我在一個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顯示出來卻一直顯示不出來 請大大們解惑 感謝~~ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 219.70.218.213 ※ 文章網址: https://www.ptt.cc/bbs/MacDev/M.1515415128.A.C07.html
gundam00: DispatchQueue.main.async{ table.text = value }試試 01/08 20:45
gundam00: 看 01/08 20:45
Sexyfather: UI 更新應該是要放在main thread 沒錯 01/08 22:41
cryinglove: 你指定delegate時,是指給另一個你初始化出來的 viewC 01/09 09:40
cryinglove: ontrollerB 01/09 09:40
whitefox0102: 一樓大大~照做了可是沒用耶Orz 01/09 11:38
whitefox0102: cryinglove大~那我應該如何做才對呢? 01/09 11:38
RINPE: 這行確定有進去嗎? itemPriceLabel!.text = price 設 01/09 12:51
RINPE: 中斷看一下 01/09 12:51
whitefox0102: 有進去但是label的值都沒有改變 01/09 13:13
booray: 看起來你 ViewControllerB() 這裏弄出來另一個 viewcontr 01/09 13:31
booray: ollerb 物件而不是顯示在螢幕上那個要不要考慮改用 notif 01/09 13:31
booray: ication 實作? 01/09 13:31
whitefox0102: 剛剛改用了notifacation了~可是這中間會頓一下 01/09 14:31
whitefox0102: 點擊按鈕傳送通知到改變Label大約要4秒 01/09 14:33
whitefox0102: 甩笨了...自己多調用了別的func,使用notifacation 01/09 14:45
whitefox0102: 後就成功實現了~感謝樓上諸位大大的幫忙^^ 01/09 14:46