Delegate using Container View in Swift

后端 未结 2 420
故里飘歌
故里飘歌 2021-02-05 23:38

I\'m developing an app for iPad Pro. In this app, containerView use to add additional views and interact with them.

First, I created a protocol

相关标签:
2条回答
  • 2021-02-06 00:23

    Like @nwales said you haven't yet set the delegate. You should do set the delegate in prepareForSegue function on your first viewController (who contain the viewContainer)

    First select the embed segue and set an identifier in the attributes inspector. Then in the parentViewController implement the func prepareForSegue like this:

    Swift 4+:

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
            if (segue.identifier == "the identifier") {
                let embedVC = segue.destination as! ViewController
                embedVC.delegate = self
            }
        }
    

    Below:

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
        if (segue.identifier == "the identifier") {
            let embedVC = segue.destinationViewController as! ContainerViewController
            embedVC.dataViewDelegate = self
        }
    }
    
    0 讨论(0)
  • 2021-02-06 00:36

    Looks like you defined the delegate, but have not set the delegate. This happens to me all the time.

    0 讨论(0)
提交回复
热议问题