【发布时间】:2017-12-14 10:09:03
【问题描述】:
我的程序卡在 await Pushmodalasync 部分时遇到问题。在您登录应用程序之前,它应该卡在那里,但是登录页面永远不会加载,它只是卡在加载屏幕上。
这在 iOS 和 Android 上是同样的问题。
正在加载登录页面
protected async override void OnAppearing()
{
if (App.Client.Initilized == false)
{
await App.Client.Init();
}
if (App.Client.LoggedIn == false)
{
ShowLoginPage();
return;
}
ShowIssuesFromCurrentLocation();
}
调用登录页面
private async void ShowLoginPage()
{
MessagingCenter.Subscribe<LoginPage>(this, "OnLoginPageClosed", (sender) =>
{
MessagingCenter.Unsubscribe<LoginPage>(this, "OnLoggedIn");
if (App.Client.LoggedIn == false)
{
Issues.Clear();
}
else
{
ShowIssuesFromCurrentLocation();
}
});
await this.Navigation.PushModalAsync(new LoginPage());
}
登录页面本身
public partial class LoginPage : ContentPage
{
public LoginViewModel data;
public LoginViewModel Data { get { return data; } }
public LoginPage()
{
this.data = App.Client.GetCurrentLoginModel();
this.BindingContext = this.data;
this.Title = "Login";
InitializeComponent();
}
登录类的xaml部分
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ASFT.IssueManager.LoginPage" Padding="10">
<ContentPage.Resources>
<ResourceDictionary>
<x:String x:Key="Labelfont">Medium</x:String>
<x:String x:Key="Titlefont">Large</x:String>
</ResourceDictionary>
</ContentPage.Resources>
<StackLayout Orientation="Vertical" VerticalOptions="Center" HorizontalOptions="FillAndExpand" Spacing="10" >
<StackLayout Orientation="Vertical" VerticalOptions="Start" HorizontalOptions="Center" Spacing="10" WidthRequest="350">
<Label Text="Login" VerticalOptions="Center" HorizontalOptions="Start" FontSize="{StaticResource Titlefont}"/>
<BoxView HeightRequest="5" Color="Gray"/>
<Label Text="Host" VerticalOptions="Center" HorizontalOptions="Start" FontSize="{StaticResource Labelfont}"/>
<Entry Placeholder="Host/URL" Text="{Binding Host}" />
<Label Text="UserName" VerticalOptions="Center" HorizontalOptions="Start" FontSize="{StaticResource Labelfont}"/>
<Entry Placeholder="User name / Account" Text="{Binding Username}" />
<Label Text="Password" VerticalOptions="Center" HorizontalOptions="Start" FontSize="{StaticResource Labelfont}"/>
<Entry Placeholder="Password" IsPassword="true" Text="{Binding Password}" />
<BoxView HeightRequest="5" Color="Gray"/>
<Button x:Name="btnLogin" Text="Login" HorizontalOptions="FillAndExpand" Clicked="OnButtonLogin" WidthRequest="100"/>
</StackLayout>
</StackLayout>
</ContentPage>
初始化组件方法
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Forms.Build.Tasks.XamlG", "0.0.0.0")] 私人无效初始化组件(){ 全局::Xamarin.Forms.Xaml.Extensions.LoadFromXaml(this, typeof(LoginPage)); btnLogin = global::Xamarin.Forms.NameScopeExtensions.FindByName(this, "btnLogin"); }
登录视图模型
public LoginViewModel GetCurrentLoginModel()
{
// DEBUG
if (state.Username.Length == 0)
state.Username = "mudemo";
if (state.Host.Length == 0)
state.Host = "";
// VERY DEBUG. - REMOVE
//String password = "4R5zE6mw";
String password = "mudemo";
return new LoginViewModel
{
// default debug account
Host = state.Host,
Username = state.Username,
Password = password
};
}
错误信息:
我正在使用 xamarinsforms 2.5.0.12,这是可用的最新稳定版本。
12-14 12:21:15.185 D/AbsListView(22659): unregisterIRListener() 是 称为 12-14 12:21:15.190 D/Mono (22659): DllImport 搜索: '__Internal' ('(null)')。 12-14 12:21:15.190 D/单声道 (22659): 搜索“java_interop_jnienv_call_nonvirtual_float_method_a”。 12-14 12:21:15.190 D/Mono (22659):探测 'java_interop_jnienv_call_nonvirtual_float_method_a'。 12-14 12:21:15.190 D/Mono (22659):发现为 'java_interop_jnienv_call_nonvirtual_float_method_a'。 12-14 12:21:15.220 D/Mono (22659): DllImport 搜索:'__Internal' ('(空值)')。 12-14 12:21:15.220 D/Mono (22659): 搜索 'java_interop_jnienv_call_void_method'。 12-14 12:21:15.225 日/单
(22659):探测“java_interop_jnienv_call_void_method”。 12-14 12:21:15.225 D/Mono (22659):发现为 'java_interop_jnienv_call_void_method'。 12-14 12:21:15.280 D/AbsListView(22659): unregisterIRListener() 被调用 12-14 12:21:19.350 D/Mono (22659):卸载图像 System.Diagnostics.Debug.dll [0x8356da00]。 12-14 12:21:19.350 日/单
(22659): 图像地址引用 System.Diagnostics.Debug[0x8356ac40] -> System.Diagnostics.Debug.dll[0x7fbf0d28]:5 12-14 12:21:19.350 D/单声道 (22659):配置尝试解析: 'System.Diagnostics.Debug.dll.config'。 12-14 12:21:19.350 日/单
(22659):配置尝试解析: '/usr/local/etc/mono/assemblies/System.Diagnostics.Debug/System.Diagnostics.Debug.config'。 12-14 12:21:19.350 D/Mono (22659): 大会参考地址 ASFT.IssueManager[0x7db3d5c0] -> System.Diagnostics.Debug[0x7fc01d28]: 3 将“LoginPage.xaml.cs:32,1”处的挂起断点解决为无效 ASFT.IssueManager.LoginPage.OnDisappearing () [0x0000d]。解决 'LoginPage.xaml.cs:31,1' 处的挂起断点无效 ASFT.IssueManager.LoginPage.OnDisappearing () [0x00001]。 12-14 12:21:24.365 D/Mono (22659):图像地址 System.Diagnostics.Tools[0x83567040] -> System.Diagnostics.Tools.dll[0x835676b0]:2 12-14 12:21:24.365 D/单声道 (22659):准备设置程序集“System.Diagnostics.Tools” (System.Diagnostics.Tools.dll) 12-14 12:21:24.365 D/Mono (22659): 装配 System.Diagnostics.Tools[0x83567040] 添加到域 根域,ref_count=1 12-14 12:21:24.365 D/Mono (22659): AOT: 找不到图像“System.Diagnostics.Tools.dll.so”:dlopen 失败: 图书馆 “/data/app-lib/com.asft.event-68/libaot-System.Diagnostics.Tools.dll.so” 未找到 12-14 12:21:24.365 D/Mono (22659): AOT: image '/usr/local/lib/mono/aot-cache/arm/System.Diagnostics.Tools.dll.so' 未找到:dlopen 失败:库 “/data/app-lib/com.asft.event-68/libaot-System.Diagnostics.Tools.dll.so” 未找到 12-14 12:21:24.365 D/Mono (22659): 配置试图 解析:'System.Diagnostics.Tools.dll.config'。 12-14 12:21:24.365 D/Mono (22659):尝试解析的配置: '/usr/local/etc/mono/assemblies/System.Diagnostics.Tools/System.Diagnostics.Tools.config'。 12-14 12:21:24.365 D/Mono (22659): 大会参考地址 ASFT.IssueManager[0x7db3d5c0] -> System.Diagnostics.Tools[0x83567040]: 2 12-14 12:21:24.365 D/Mono (22659):大会参考地址 System.Diagnostics.Tools[0x83567040] -> System[0x7ed17940]:12 12-14 12:21:26.585 W/Mono (22659):加载程序集的请求 mscorlib v4.0.0.0 已重新映射到 v2.0.5.0 12-14 12:21:26.585 D/Mono
(22659):正在卸载图像 mscorlib.dll [0x835670b0]。 12-14 12:21:26.585 D/Mono (22659):尝试解析的配置:“mscorlib.dll.config”。 12-14 12:21:26.585 D/Mono (22659):配置尝试解析: '/usr/local/etc/mono/assemblies/mscorlib/mscorlib.config'。 12-14 12:21:26.585 D/Mono (22659):卸载图像 System.Globalization.dll [0x83579b48]。 12-14 12:21:26.585 日/单
(22659): 图像地址引用 System.Globalization[0x8357a8b0] -> System.Globalization.dll[0x7f17f3d0]: 6 12-14 12:21:26.585 D/Mono
(22659):配置尝试解析: 'System.Globalization.dll.config'。 12-14 12:21:26.585 日/单
(22659):配置尝试解析: '/usr/local/etc/mono/assemblies/System.Globalization/System.Globalization.config'。 12-14 12:21:26.585 D/Mono (22659): 大会参考地址 Xamarin.Forms.Xaml [0x7dbd5a78]-> System.Globalization [0x7f17ffd8]:4 加载的程序集:System.Diagnostics.Tools.dll [外部] 12-14 12:21:26.600 W/Mono (22659):加载程序集的请求 mscorlib v4.0.0.0 已重新映射到 v2.0.5.0 12-14 12:21:26.600 D/Mono
(22659):正在卸载图像 mscorlib.dll [0x835670b0]。 12-14 12:21:26.600 D/Mono (22659):尝试解析的配置:“mscorlib.dll.config”。 12-14 12:21:26.600 D/Mono (22659):配置尝试解析: '/usr/local/etc/mono/assemblies/mscorlib/mscorlib.config'。 12-14 12:21:26.805 D/Mono (22659):卸载图像 System.Runtime.Extensions.dll [0x8359dec8]。 12-14 12:21:26.805 D/单声道 (22659): 图片地址 System.Runtime.Extensions[0x83595340] -> System.Runtime.Extensions.dll[0x7eb780b0]:6 12-14 12:21:26.805 D/单声道 (22659):配置尝试解析: 'System.Runtime.Extensions.dll.config'。 12-14 12:21:26.805 日/单
(22659):配置尝试解析: '/usr/local/etc/mono/assemblies/System.Runtime.Extensions/System.Runtime.Extensions.config'。 12-14 12:21:26.805 D/Mono (22659): 大会参考地址 Xamarin.Forms.Xaml[0x7dbd5a78] -> System.Runtime.Extensions[0x7eb77b68]:4 12-14 12:21:31.060 I/Choreographer(22659):跳过了 946 帧!该应用程序可能是 在其主线程上做太多工作。 12-14 12:21:31.075 D/AbsListView(22659): unregisterIRListener() 被称为 Unhandled 例外:System.ArgumentNullException:值不能为空。参数名称: 来源
应用启动
public App()
{
Client = new AppIssueClient();
// The root page of your application
MainPage = GetMainPage();
}
public async void Init()
{
await Client.Init();
}
public static Page GetMainPage()
{
var p = new NavigationPage(new IssuesPage(-1));
App.Navigation = p.Navigation;
return p;// new NavigationPage(new HomePage());
}
【问题讨论】:
-
你需要在 OnAppearing() 中等待 ShowLoginPage()。
-
嗯,所做的只是让它在返回后崩溃。活动被销毁时由于生命周期回调导致的空引用错误,可以在那里编辑崩溃
-
你能展示你的 LoginModel 吗?
-
我添加了 LoginModel,但我不确定它是否相关。 :)
-
在您的 xaml 中您绑定用户名和密码,但在您的 ViewModel 中您没有此字段。并且 ViewModel 必须实现 INotifyPropertyChanged
标签: android ios xaml xamarin xamarin.forms