son
son

Reputation: 67

The tap on the addChild viewController does not work

I am making a drawer menu.

The tableView is on top of the DrawerMenuViewController that was addChild to the ParentViewController.

When you open the drawer and tap the tableView cell on DrawerMenuViewController, there is no response.

Why can't I tap the tableView Cell?

DrawerMenuViewController is just to the left of ParentViewController. Because DrawerMenuViewController wants to come out from the right according to swipe

- TabBarController
  - NavigationController
    - ParentViewController
      - DrawerMenuViewController
class ParentViewController: UIViewController {

    override func viewDidLoad() {   
        super.viewDidLoad()
        menuViewController = DrawerMenuViewController()
        menuViewController.view.frame = CGRect(
            x: view.frame.maxX,
            y: 0,
            width: view.bounds.width,
            height: UIScreen.main.bounds.height)
        view.addSubview(menuViewController.view)
        addChild(menuViewController)
        menuViewController.didMove(toParent: self)
    }
}

Supplement

DrawerMenuViewController is just to the left of ParentViewController. Because DrawerMenuViewController wants to come out from the right according to swipe

enter image description here

Upvotes: 1

Views: 187

Answers (1)

cora
cora

Reputation: 2102

  1. One reason why didSelectRowAt function not getting called is, even though you say you've set who the delegate is that the tableView was not setup correctly.

Just to make sure that you've set the delegate and datasource in in the right place:

extension ParentViewController: UITableViewDelegate, UITableViewDataSource {

} and in ParentViewController's viewDidLoad()

tableView.delegate = self
tableView.dataSource = self

XCode will ask if you want to insert required function stubs.

  1. When you do

    menuViewController.view.frame = CGRect( x: view.frame.maxX, y: 0, width: view.bounds.width, height: UIScreen.main.bounds.height)

it looks like your origin is out of bounds because of the x coordinates

Upvotes: 1

Related Questions