Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.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 选项卡栏项作为按钮_Ios_Swift_Xcode - Fatal编程技术网

Ios 选项卡栏项作为按钮

Ios 选项卡栏项作为按钮,ios,swift,xcode,Ios,Swift,Xcode,在我的选项卡栏中有5个选项卡栏项目,其中4个有导航控制器的分段,这些分段可以引导查看控制器。我想让中间的选项卡栏项目充当一个按钮,这样当我点击它时,我就可以控制发生了什么 当前,我的中间选项卡栏项目也连接到导航控制器,这是不正确的,因为现在当我单击选项卡栏项目时,它会打开一个黑色的导航控制器。如何将中间的选项卡栏项转换为按钮,而不是导航控制器 如果我删除导航控制器,它也会从选项卡栏中删除选项卡栏项。如果希望选项卡栏项用作按钮,可以将UITabBarController子类化并实现此委托功能: f

在我的选项卡栏中有5个选项卡栏项目,其中4个有导航控制器的分段,这些分段可以引导查看控制器。我想让中间的选项卡栏项目充当一个按钮,这样当我点击它时,我就可以控制发生了什么

当前,我的中间选项卡栏项目也连接到导航控制器,这是不正确的,因为现在当我单击选项卡栏项目时,它会打开一个黑色的导航控制器。如何将中间的选项卡栏项转换为按钮,而不是导航控制器


如果我删除导航控制器,它也会从选项卡栏中删除选项卡栏项。

如果希望选项卡栏项用作按钮,可以将UITabBarController子类化并实现此委托功能:

func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {

        // Check if bar item selected is center
        if viewController.tabBarItem.tag == 2 {


            // Do Something Here ...


            // Present View Controller
            guard let navigationController = storyboard?.instantiateViewController(withIdentifier: "NavigationController") as? UINavigationController else { return false }

            present(navigationController, animated: true)

            // Returning false will not open the connected tab bar item view controller you attached to it
            return false

        }

        // Return true to open the connected tab bar item view controller you attached to it (e.x. everything but the center item)
        return true
    }

实现自定义选项卡栏并像普通按钮一样使用选项卡栏项

将新的选项卡栏视图添加到视图控制器VC 添加所需的自定义选项卡栏项,并在属性检查器上为其指定标记号 将代理出口从选项卡栏视图添加到视图控制器右键单击并拖动到VC 在视图控制器上,子类uitabardelegate,如下所示 实现这个委托函数,那么它应该可以工作
不是我要找的。我不希望在我的选项卡栏项目上方有一个按钮,我希望其中一个选项卡栏项目用作按钮,而不是导航操作。您必须创建自定义UITabBarController并访问其委托函数来处理选项卡栏项目shouldSelect事件;当有人选择一个项目时,让你完全控制该做什么。
class ViewController: UIViewController, UITaBarDelegate {}
func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
    if item.tag == 1 {
        //Do something

    }
    if item.tag == 2 {
        //Do something
    }
    .......
}