如果我理解正确,您希望您的初始 ViewController 成为 TabViewController,并且当用户在其中一个 ViewController 中选择某些内容时,它会转换为 ViewController 而底部没有 TabView 按钮。
如果是这样,这就是您需要做的。
在 AppDelegate.cs 中,您需要像这样设置窗口/视图控制器:
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
window = new UIWindow (UIScreen.MainScreen.Bounds);
rootController = new UINavigationController ();
window.RootViewController = rootController;
var tabController = new UITabBarController ();
var vc1 = new TestController1();
var vc2 = new TestController2();
var vc3 = new TestController3();
tabController.ViewControllers = new UIViewController[] {
vc1,
vc2,
vc3
};
tabController.ViewControllers [0].TabBarItem.Title = "vc1";
tabController.ViewControllers [1].TabBarItem.Title = "vc2";
tabController.ViewControllers [2].TabBarItem.Title = "vc3";
this.rootController.PushViewController(tabController, false);
window.MakeKeyAndVisible ();
return true;
}
完成此设置后,您可以从 TestController1 的类中转换到新视图,如下所示:
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
var button = UIButton.FromType(UIButtonType.RoundedRect);
button.Frame = new RectangleF (10, 10, 200, 30);
button.SetTitle ("Go Child Controller", UIControlState.Normal);
button.TouchUpInside += (object sender, EventArgs e) => {
NavigationController.PushViewController(new TestController4(), true);
};
View.AddSubview (button);
}
此外,您可以简化设置选项卡按钮标题。
而不是这样做:
tabController.ViewControllers [0].TabBarItem.Title = "vc1";
你可以在你的子 UIViewController 中设置标题:
public class TestController1:UIViewController
{
public TestController1 ()
{
this.Title = "vc1";
}
...