Article From:

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()


class HomePageView: UIView {

 fileprivate lazy var leftSideMenuView:LeftSideMenuView = LeftSideMenuView()
  override init(frame: CGRect) {
    super.init(frame: frame)
  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.

Leave a Reply

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