2012-05-09 20 views

回答

7

MvvmCross從所有ViewModel只是「普通頁面」的前提開始 - 所以在iOS/MonoTouch中意味着使用UINavigationController呈現的UIViewControllers。

要擺脫這個前提 - 朝着標籤式顯示器,模式顯示器,分體式控制器,彈出式窗口等 - 您可以在MonoTouch應用程序中調整Presenter邏輯。

演示者的工作就是實現:

public interface IMvxTouchViewPresenter 
{ 
    void Show(MvxShowViewModelRequest view); 
    void Close(IMvxViewModel viewModel); 
    void CloseModalViewController(); 
    void ClearBackStack(); 
    bool PresentModalViewController(UIViewController controller, bool animated); 
    void NativeModalViewControllerDisappearedOnItsOwn(); 
} 

用於您的應用程序的演示中的AppDelegate建設選擇 - 例如看看TwitterSearch如何爲iPhone和iPad構建不同的演示者。


幸運的是,簡單的模態的支持,提供了標準的主持人之一是MvxModalSupportTouchViewPresenter.cs

這主持人查看是否被提出的觀點有IMvxModalTouchView標記接口 - 它測試view is IMvxModalTouchView。如果這個界面存在,那麼它使用視圖的模態呈現而不是「正常導航」。

要使用此功能,您的AppDelegate代碼更改爲:

public override bool FinishedLaunching(UIApplication app, NSDictionary options) 
    { 
     window = new UIWindow(UIScreen.MainScreen.Bounds); 

     // initialize app for single screen iPhone display 
     var presenter = new MvxModalSupportTouchViewPresenter(this, window); 
     var setup = new Setup(this, presenter); 
     setup.Initialize(); 

     // start the app 
     var start = this.GetService<IMvxStartNavigation>(); 
     start.Start(); 

     window.MakeKeyAndVisible(); 

     return true; 
    } 

然後標記接口添加到您的視圖模式(S):

public class MyView : MvxBindingTouchViewController<MyViewModel>, IMvxModalTouchView 
{ 
     // .... 
} 
+1

尼斯一個斯圖爾特。順便說一下,偉大的框架。這是一個大型項目的基礎。 – Kevin

+0

很酷 - 如果您有小問題,請在http://jabbr.net/#/rooms/mvvmcross上找到我們,否則,使用SO是完美的 – Stuart

+0

另外,對於任何合理大小的iPhone/iPad應用程序,我希望您在某些時候最終會寫出自己的主持人 - 尤其是iPad。 – Stuart

相關問題