Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.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
如何在Xamarin iOS中隐藏TabBarItem_Xamarin_Tabs_Xamarin.ios - Fatal编程技术网

如何在Xamarin iOS中隐藏TabBarItem

如何在Xamarin iOS中隐藏TabBarItem,xamarin,tabs,xamarin.ios,Xamarin,Tabs,Xamarin.ios,我有一个带有TabBarController和六个子视图作为选项卡的故事板。TabBarController,每个选项卡都分配了一个控制器类。 某些选项卡的内容是从服务器加载的。在某些情况下,选项卡没有内容,在这种情况下,我想隐藏TabBarItem 我试过(只是为了测试) 但它不起作用 如何隐藏一个TabBarItems?我搜索过谷歌、StackOverflow和Xamarin论坛,但没有找到解决我问题的方法。 我找到的唯一解决方案是从子视图数组中删除子视图,但在这种情况下,如果我想再次显示选

我有一个带有
TabBarController
和六个子视图作为选项卡的故事板。
TabBarController
,每个选项卡都分配了一个控制器类。 某些选项卡的内容是从服务器加载的。在某些情况下,选项卡没有内容,在这种情况下,我想隐藏TabBarItem

我试过(只是为了测试)

但它不起作用

如何隐藏一个TabBarItems?我搜索过谷歌、StackOverflow和Xamarin论坛,但没有找到解决我问题的方法。 我找到的唯一解决方案是从子视图数组中删除子视图,但在这种情况下,如果我想再次显示选项卡,我不能简单地“重新激活”选项卡。

对于UITabBar:

UITabBar sampleTabBar;

public override void ViewDidLoad ()
        {
            base.ViewDidLoad ();
            // Perform any additional setup after loading the view, typically from a nib.

            sampleTabBar = new UITabBar ();
            sampleTabBar.Frame = new CoreGraphics.CGRect (10f, 64f, this.View.Frame.Width - 10, 50f);

            var tabBarItem = new UITabBarItem ("TAB BAR ITEM", null, 4);
            sampleTabBar.Items = new UITabBarItem[]{ tabBarItem };
            sampleTabBar.ItemSelected += (sender, e) => {
                Console.WriteLine ("tab bar button item slected");

             //Disable Tab Bar item here
                tabBarItem.Enabled = false;
                tabBarItem.Title = "Disabled now";
            };

            this.View.AddSubview (sampleTabBar);
        }
图像属性也可用于获取结果

1) Set a placeholder image as default.
2) Populate images from array/source to uibarButtonItem.
3) Use placeholder image wherever need to hide uibarbuttonitem.

我认为,如果要完全隐藏
uitabaritem
,需要从
UITabbarController
中删除
UIViewController
,如下所示:

    var tbViewControllers = new List<UIViewController> (TabBarController.ViewControllers);
    tbViewControllers.RemoveAt (2); // remove whatever index you need.
    TabBarController.ViewControllers = tbViewControllers.ToArray ();

谢谢你的回答。但通过这种方式,TabBarItem仍然可见,只是被停用了。我想完全隐藏TabBarItem。
    var tbViewControllers = new List<UIViewController> (TabBarController.ViewControllers);
    tbViewControllers.RemoveAt (2); // remove whatever index you need.
    TabBarController.ViewControllers = tbViewControllers.ToArray ();
    var tbViewControllers = new List<UIViewController> (TabBarController.ViewControllers);
    tbViewControllers.Insert (2, new RemvoedViewController());
    TabBarController.ViewControllers = tbViewControllers.ToArray ();