Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 为什么UITableView没有像它那样获得任何用户交互';s ViewController作为子视图添加到UITabBarController_Ios_Swift_Uitableview_Uiviewcontroller_Uitabbar - Fatal编程技术网

Ios 为什么UITableView没有像它那样获得任何用户交互';s ViewController作为子视图添加到UITabBarController

Ios 为什么UITableView没有像它那样获得任何用户交互';s ViewController作为子视图添加到UITabBarController,ios,swift,uitableview,uiviewcontroller,uitabbar,Ios,Swift,Uitableview,Uiviewcontroller,Uitabbar,我正在以编程方式将左侧菜单设置为UITabBarController。为此,我在TabBarController中插入一个索引为0的viewController作为子视图。当我按下菜单图标时,第一个选项卡向右移动,菜单UITableView显示,但我无法与UITableView交互,我哪里出错了 总计UITabBarController.swift文件 import UIKit class MainTabBarController: UITabBarController { // MARK

我正在以编程方式将左侧菜单设置为
UITabBarController
。为此,我在
TabBarController
中插入一个索引为0的viewController作为子视图。当我按下菜单图标时,第一个选项卡向右移动,菜单
UITableView
显示,但我无法与
UITableView
交互,我哪里出错了

总计
UITabBarController.swift
文件

import UIKit

class MainTabBarController: UITabBarController {

// MARK: Properties

var menuController: MenuController!
var centerController: UIViewController!
var isExpanded = false

// MARK: Initialization

override func viewDidLoad() {
    super.viewDidLoad()
    configureHomeController()
}

override var preferredStatusBarStyle: UIStatusBarStyle {
    return .lightContent
}

override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation {
    return .slide
}

override var prefersStatusBarHidden: Bool {
    return isExpanded
}

// MARK: Handlers

func configureHomeController() {
    let navigationController = self.viewControllers![0] as! UINavigationController
    let homeController =  navigationController.viewControllers[0] as! FirstViewController
    homeController.homeControllerDelegate = self
    centerController = homeController
}

//Configuring Side Menu Controller

func configureMenuController() {
    if menuController == nil {
        // add menu controller here
        menuController = MenuController()
        menuController.homeControllerDelegate = self
        // Add Child View Controller
        addChild(menuController)
        // Add Child View as Subview
        view.insertSubview(menuController.view, at: 0)
        // Configure Child View
        menuController.view.frame = view.bounds
        menuController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        // Notify Child View Controller
        menuController.didMove(toParent: self)
    }
}

func animateSideMenuOpeningAndClosing(shouldExpand: Bool, menuItem: MenuItem?) {
    if shouldExpand {
        // Show Menu
        UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: .curveEaseInOut, animations: {
            self.centerController.view.frame.origin.x = self.centerController.view.frame.width - 80
        }, completion: nil)
    } else {
        // Hide Menu
        UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0,options: .curveEaseInOut, animations: {
            self.centerController.view.frame.origin.x = 0
        }) { (_) in
            guard let menuItem = menuItem else {return}
            self.didSelectMenuItem(menuItem: menuItem)
        }
    }
    animateStatusBar ()
}

func didSelectMenuItem(menuItem: MenuItem) {
    switch menuItem {
    case .Dashboard:
        print("Show Dashboard")
    case .Profile:
        print("Show Profile")
    case .Notifications:
        print("Show Notifications")
    case .Contacts:
        let controller = SettingsController()
        controller.username = "YAMIN"
        present(UINavigationController(rootViewController: controller), animated: true, completion: nil)
    }
}

func animateStatusBar () {
    UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0,options: .curveEaseInOut, animations: {
        self.setNeedsStatusBarAppearanceUpdate()
    }, completion: nil)
}

}

extension MainTabBarController: HomeControllerDelegate {
func handleMenuToogle(forMenuItem menuItem: MenuItem?) {
    print("Pressed")
    if !isExpanded {
        configureMenuController()
    }
    isExpanded = !isExpanded
    animateSideMenuOpeningAndClosing(shouldExpand: isExpanded, menuItem: menuItem)
}

}

在0索引处插入子视图,因此,我认为有些视图在子视图层次结构中更高

您可以使用“调试视图层次结构按钮”查看子视图