0

5 つの TabBar ビューがあります... アプリの初回起動時に表示されるビューを選択するにはどうすればよいですか? (アプリの開始時に null であるデータを使用していくつかの計算があります)。FinishedLaunching に到達する前に、アプリがクラッシュします。そして、どのビューが最初のビューになるかをどのように決定するのでしょうか?

以前の回答で、tabBarController.SelectedIndex = 0; が提案されました。(私は MonoTouch を使用しています)しかし、どこに配置するか教えてくれませんでした。

4

2 に答える 2

1

You should create your view controllers in ViewDidLoad of the UITabBarController, not in the ViewDidAppear. I use the code below (first part is in your AppDelegate class):

    // WARNING: Do not make these variables local. MonoTouch will loose the reference to them!
    private UIWindow _mainWindow;
    private MainTabBarController _mainTabBarController;

    public override bool FinishedLaunching(UIApplication app, NSDictionary options)
    {
        _mainWindow = new UIWindow(UIScreen.MainScreen.Bounds);
        _mainTabBarController = new MainTabBarController();
        _mainWindow.AddSubview(_mainTabBarController.View);
        _mainWindow.MakeKeyAndVisible ();
        return true;
    }

Your MainTabBarController class should look like this:

public class MainTabBarController : UITabBarController
{
    public override void ViewDidLoad ()
    {
        ViewControllers = new UIViewController[]
        {
            new ViewControllerTab1(),
            new ViewControllerTab2(),
            new ViewControllerTab3(),
            new ViewControllerTab4(),
            new ViewControllerTab5()
        };
        SelectedIndex = 2;
    }
}

This will show Tab3 (with index 2) at startup.

ViewControllerTab1 etc. are classes derived from eg. UIViewController or UINavigationController which implement their user interface in their own ViewDidLoad()

于 2011-01-04T10:36:06.103 に答える
0
var u = new UIViewController[]
{
   tab1,
   tab2,
   tab3,
   tab4,
   tab5,
};

this.ViewControllers = u;
this.SelectedViewController = tab1;

通常、UITabBarController をサブクラス化し、オーバーライドする ViewDidAppear メソッドに上記のコードを追加します。

于 2010-12-30T21:29:53.717 に答える