Article From:https://segmentfault.com/q/1010000011713510
Question:

As shown, I wrote a protocol to be sent back from view to viewcontroller.



However, the object hierarchy is HomePageViewController -> HomePageView -> LeftSideMenuView.

I have some big questions and I mean, “because I didn’t get in”? No entry? I don’t understand. Is this writing not right? I’m sorry, because little sister really didn’t know the principle, just using hard back.

I would like to ask you, what is the correct way to write? (it has been stuck here for two days…)

Answer 0:

protocol onSideMenuButtonAction {

 func leftButtonAction(type:String)

}

class HomePageViewController: UIViewController,onSideMenuButtonAction {

var homePageView:HomePageView{ return self.view as! HomePageView }
override func loadView() {
    view = HomePageView()
    homePageView.bindTo(action:self)
    }

}

class HomePageView: UIView {

 fileprivate lazy var leftSideMenuView:LeftSideMenuView = LeftSideMenuView()
  override init(frame: CGRect) {
    super.init(frame: frame)
    addSubview(leftSideMenuView)  
  }
  func bindTo(action: onSideMenuButtonAction) {
    leftSideMenuView.sideMenuAction = action
   }
    func onButtonAction(sender:SideMenuButton) {
        self.sideMenuAction?.leftButtonAction(type: text)
    }

}
class LeftSideMenuView: UIView {

var sideMenuAction:onSideMenuButtonAction?

}

Set up a relay in the middle.

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *