これは私のアプリでタブを使う方法です。私はMvvmCross 4.4.0を使用しています。
AppDelegate.cs:
[Register("AppDelegate")]
public partial class AppDelegate : MvxApplicationDelegate
{
private UIWindow window;
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
this.window = new UIWindow(UIScreen.MainScreen.Bounds);
Setup setup = new Setup(this, this.window);
setup.Initialize();
IMvxAppStart startup = Mvx.Resolve<IMvxAppStart>();
startup.Start();
this.window.MakeKeyAndVisible();
return true;
}
}
Setup.cs:
public class Setup : MvxIosSetup
{
public Setup(MvxApplicationDelegate applicationDelegate, UIWindow window) : base(applicationDelegate, window)
{
}
protected override IMvxApplication CreateApp()
{
return new Core.App();
}
}
HomeView.cs:
public class HomeView : MvxTabBarViewController<HomeViewModel>
{
private bool _constructed;
public HomeView()
{
_constructed = true;
// need this additional call to ViewDidLoad because UIkit creates the view before the C# hierarchy has been constructed
ViewDidLoad();
}
public override void ViewDidLoad()
{
if (!_constructed)
return;
base.ViewDidLoad();
var viewControllers = new UIViewController[]
{
CreateTabFor(0, "First", "FirstImage", typeof(FirstViewModel)),
CreateTabFor(1, "Second", "SecondImage", typeof(SecondViewModel)),
CreateTabFor(2, "Third", "ThirdImage", typeof(ThirdViewModel))
};
ViewControllers = viewControllers;
CustomizableViewControllers = new UIViewController[] { };
//Sometimes I need to start with a specific tab selected
SelectedViewController = ViewControllers[ViewModel.CurrentPage];
}
private UIViewController CreateTabFor(int index, string title, string imageName, Type viewModelType)
{
var controller = new UINavigationController();
var request = new MvxViewModelRequest(viewModelType, null, null, null);
var viewModel = Mvx.Resolve<IMvxViewModelLoader>().LoadViewModel(request, null);
var screen = this.CreateViewControllerFor(viewModel) as UIViewController;
screen.Title = title;
screen.TabBarItem = new UITabBarItem(title, UIImage.FromBundle(imageName), index);
controller.PushViewController(screen, true);
return controller;
}
}
FirstView.cs、SecondView.cs、ThirdView.csおよびすべての他のタブ付きビュー:
public class FirstView : MvxViewController<FirstViewModel>
{
public override void ViewDidLoad()
{
base.ViewDidLoad();
//Your view content...
}
}
AndroidおよびiOS搭載のGithubリポジトリサンプル:https://github.com/rrispoli/SampleTabs
ラファエル - これは非常に役に立ちます。あなたはこのアプローチを使ってiosとandroidで動作するタブメニューを表示するGitHubの例へのリンクを投稿することができますか?私はあなたの好きな慈善団体に喜んで寄付します! :) –
はい、私は次の日にサンプルプロジェクトを作成し、ここにGitHubリンクを残します。 :) –
こんにちはラファエル、そのサンプルプロジェクトを投稿する機会があれば、それは高く評価されます:) –