问题描述
由于我是Xamarin.IOS的新手,所以我想问一个问题.我遵循了此示例在Xamarin.IOS项目中添加UITabBarController.
As I'm new in Xamarin.IOS, I'd like to ask a question.I've followed this example for adding UITabBarController in a Xamarin.IOS project.
当我通过TabController的实例初始化RootViewController时,它可以正常工作,并且我具有所有选项卡.但是我的NavigationController设置为null!这意味着:
When I initialized RootViewController by an instance of TabController, it works fine and I have all tabs.BUT my NavigationController set null ! it means that :
- NavigationItem将消失
-
无法通过此代码在viewController之间导航:
- NavigationItem will disappear
navigating between viewControllers are not possible by this code :
this.NavigationController.PushViewController(new ProfileViewController(), true);
因为NavigationController为null!这是我在AppDelegate中的代码:
because the NavigationController is null !Here is my code in AppDelegate:
_tabController = new TabController();
_window.RootViewController = _tabController;
和我的TabController:
and my TabController :
public class TabController : UITabBarController
{
UIViewController tab1, tab2, tab3, tab4;
public TabController()
{
tab1 = new HomeViewController();
tab1.TabBarItem.Image = UIImage.FromFile("Icons/Home.png");
tab2 = new TagCategoryViewController(null, null, 1, null);
tab2.TabBarItem.Image = UIImage.FromFile("Icons/Tag.png");
tab3 = new SearchViewController();
tab3.TabBarItem.Image = UIImage.FromFile("Icons/Search.png");
tab4 = new ProfileViewController();
tab4.TabBarItem.Image = UIImage.FromFile("Icons/Home.png");
var tabs = new UIViewController[] {
tab1, tab2, tab3,tab4
};
ViewControllers = tabs;
}
}
此外,我有很多UIViewControllers,我都是通过编程方式完成的,因此我不使用StoryBoard!
In additional, I have lots of UIViewControllers and I do all of them programmatically and I dont use StoryBoard !
推荐答案
通过将TabController
包装在UINavigationController
中.
_tabController = new TabController();
_window.RootViewController = new UINavigationController(_tabController);
这样,NavigationController属性将不会为null,并且可以完成导航.
This way NavigationController property won't be null and navigation can be done.
这篇关于添加UITabBarController并且没有NavigationController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!