问题描述
当我使用 MvvmCross 5 时,我编写了所有视图,并通过在我的 AppDelegate
中编写此代码来避免在我的 iOS 应用程序中使用故事板:
[Register("AppDelegate")]
public class AppDelegate : MvxApplicationDelegate
{
private MvxIosViewPresenter viewPresenter;
public override UIWindow Window
{
get;
set;
}
/// <summary>
/// MvvmCross Mods:
/// - Creates a new presenter,which determines how Views are shown
/// - This example uses a standard presenter.
/// </summary>
/// <param name="application"></param>
/// <param name="launchOptions"></param>
/// <returns></returns>
public override bool FinishedLaunching(UIApplication application,NSDictionary launchOptions)
{
// create a new window instance based on the screen size
Window = new UIWindow(UIScreen.MainScreen.Bounds);
// MvvmCross Mod Start---------------------------------------------
// This class will determine how Views are shown
this.viewPresenter = new MvxIosViewPresenter(this,Window);//new ViewPresenter(Window);
// Init the Setup object,which initializes App.cs
var setup = new Setup(this,this.viewPresenter);
setup.Initialize();
//this.viewPresenter.PresentModalViewController(new ListenViewController(),true);
// Use IoC to find and start the IMvxAppStart object
var startup = Mvx.Resolve<IMvxAppStart>();
startup.Start();
// MvvmCross Mod End--------------------------------------------------
// make the window visible
Window.MakeKeyAndVisible();
return true;
}
public class Setup : MvxIosSetup
{
public Setup(MvxApplicationDelegate appDelegate,IMvxIosViewPresenter presenter)
: base(appDelegate,presenter)
{
}
protected override IMvxApplication CreateApp()
{
return new Core.App();
}
protected override IMvxTrace CreateDebugTrace()
{
return new DebugTrace();
}
}
但是在 MvvmCross 6.4.2 中,MvxIosSetup
没有接受 2 个参数的基本构造函数。相反,我有:
[Register(nameof(AppDelegate))]
public partial class AppDelegate : MvxApplicationDelegate<Setup,App>
{
}
public class Setup : MvxIosSetup<App>
{
}
如何配置它以便我可以在没有故事板的情况下对视图进行编码?
编辑
我使用 MvvmCross 7 创建了一个非常小的示例应用程序,其中包含 1 个视图模型/控制器。ViewDidLoad
方法从未在我的 MainViewController
中被调用。有人可以告诉我为什么吗?我把我的代码放在这里:
https://github.com/sinight95/TestApp/tree/main/TestApp
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)