我的目标是在空闲超时后将用户重定向回登录屏幕。每次点击/触摸后,我都有这段代码进行倒计时。它运行良好,但我目前的问题是我不知道将用户重定向回登录屏幕。由于这是 MvvmCross 4.4 项目,因此没有太多文档可供查找。如果我也可以获得 Android 的示例代码,那将非常有帮助。我会感激的。下面是我放在 Main.cs 中的代码public class Application{ static void Main(string[] args){ //UIApplication.Main(args, null, "AppDelegate"); UIApplication.Main(args, "MyApplication", "AppDelegate"); } } //DELEGATE [Register("MyApplication")] public class MyApplication : UIApplication { public override void SendEvent(UIEvent uievent) { base.SendEvent(uievent); var allTouches = uievent.AllTouches; if (allTouches.Count > 0) { var phase = ((UITouch)allTouches.AnyObject).Phase; if (phase == UITouchPhase.Began || phase == UITouchPhase.Ended) ResetIdleTimer(); } } NSTimer idleTimer; void ResetIdleTimer() { if (idleTimer != null) { idleTimer.Invalidate(); idleTimer.Dispose(); } idleTimer = NSTimer.CreateScheduledTimer(TimeSpan.FromMinutes(0.5), TimerExceeded); } void TimerExceeded(NSTimer obj) { MvxiOSToastService toastService = new MvxiOSToastService(); toastService.DisplayMessageAndDoSomething("You are going to be timed out.","Idle time exceeded.", RedirectToLogin); Console.WriteLine("idle time exceeded"); } void RedirectToLogin() { var window = UIApplication.SharedApplication.KeyWindow; var vc = window.RootViewController; //ERROR HERE var nextVC = new LoginView(); vc.ShowViewController(nextVC, this); //---------- } }
1 回答
幕布斯7119047
TA贡献1794条经验 获得超8个赞
您需要解析视图展示器的实例并从那里获取当前呈现的视图。一旦你有了它,你就可以访问 ViewModel 对象并进行以下调用以使用 MvvmCross 导航。
如果您有权访问RootViewControllerthen
void RedirectToLogin() {
var window = UIApplication.SharedApplication.KeyWindow;
var vc = window.RootViewController;
var mvxView = vc as IMvxIosView;
var vm = mvxView.ViewModel;
vm.ShowViewModel<TViewModel>();
}
MvvmCross 在 5 之前
https://www.mvvmcross.com/documentation/fundamentals/view-presenters
ShowViewModel<TViewModel>()
Mvvm 交叉 5+
解析导航服务的一个实例,并使用它来对登录屏幕进行导航调用。
所以像:
Mvx.Resolve<IMvxNavigationService>().Navigate<LoginViewModel>();
- 1 回答
- 0 关注
- 145 浏览
添加回答
举报
0/150
提交
取消