【发布时间】:2018-01-22 09:26:06
【问题描述】:
我有两个控制器,一个控制器是 controllerOne.swift,在这个控制器中我收到通知,我需要当一个通知到达时,在 controllerTwo.swift 上显示一个按钮。
我的代码是:
ControllerOne.swift
public func websocket(token: Any){
self.ws.open("ws://"+String(APIHOST)+":"+String(port)+"/ws?token="+String(describing: token))
self.ws.event.message = { message in
let res = self.convertToDictionary(text: message as! String)
if ((res!["notification"]) != nil) {
self.count_total_notifications_ws = self.count_total_notifications_ws! + 1
let presentView = UIApplication.shared.keyWindow?.rootViewController?.presentedViewController as? SWRevealViewController
let tabbarController = presentView?.frontViewController as? UITabBarController
if (tabbarController?.selectedIndex != 0) {
tabbarController?.tabBar.items?[0].badgeValue = self.count_total_notifications_ws?.description
}else{
//Here I need to show a showNotificationsbtn button
}
}
}
}
ControllerTwo.swift
class NewDashboardViewController: UIViewController, UITableViewDataSource, UITabBarControllerDelegate, UITableViewDelegate {
//This is the button that I need show
@IBOutlet weak var showNotificationsbtn: UIButton!
@IBAction func showNotifications(_ sender: Any) {true
self.viewDidAppear(true)
showNotificationsbtn.isHidden = true
}
}
有人知道我该怎么做吗? 感谢您的帮助。
【问题讨论】:
-
你能详细说明你说的是哪个按钮,是ControllerOne还是ControllerTwo?
-
对,就是controllerTwo的showNotificationsbtn按钮,就是我要显示的那个