【发布时间】:2018-07-05 16:05:56
【问题描述】:
我有一个父 VC,其中一个子 VC 嵌入在容器中。两个 VC 都符合委托,但只调用子委托方法。如何让两个 VC 的委托方法都做出响应?我是否缺少容器视图的委托模式?提前感谢您的帮助。
中心班:
public protocol BLEManagerDelegate: class {
func bLEManagerShowAlert(message: String)
}
public class BLEManager: NSObject {
static let sharedInstance = BLEManager()
weak var delegate: BLEManagerDelegate?
public func postMessage() {
delegate?.bLEManagerShowAlert(message: message)
}
}
父VC
class HomeVC: ContentViewController, BLEManagerDelegate {
var bLEManager = BLEManager.sharedInstance
override func viewWillAppear(_ animated: Bool) {
bLEManager.delegate = self
}
// delegate methods
func bLEManagerShowAlert(message: String) {
// THIS METHOD IS NOT GETTING CALLED
}
}
嵌入到 ParentVC 中的容器视图
class ChildVC: UITableViewController, BLEManagerDelegate {
var bLEManager = BLEManager.sharedInstance
override func viewWillAppear(_ animated: Bool) {
bLEManager.delegate = self
// delegate methods
func bLEManagerShowAlert(message: String) {
// This method IS getting called
}
}
【问题讨论】: