【发布时间】:2017-07-19 21:56:49
【问题描述】:
我是 Xamarin iOS 开发的新手,遇到了一个我无法解决的问题。当下面这行代码运行时,它会抛出一个空引用异常,我不知道为什么。
this.NavigationController.PushViewController(location, true);
这是我的整个代码块。
partial void BtnLogin_TouchUpInside(UIButton sender)
{
if (txtPassword.Text != "" && txtUsername.Text != "")
{
//send UN & PD to webservice for validation.
xxx.xxx.xxx.Services s = new xxx.xxx.xxx.Services();
bool result = s.validateLogin(txtUsername.Text, txtPassword.Text);
if (result)
{
try
{
LocationViewController location = this.Storyboard.InstantiateViewController("LocationViewController") as LocationViewController;
if (location != null)
this.NavigationController.PushViewController(location, true);
}
catch (Exception ex)
{
LoginFail("Error", ex.Message);
}
}
else
{
LoginFail("Login", "Invalid username or password.");
}
}
else
{
LoginFail("Login", "You must enter both your username and password.");
}
}
【问题讨论】:
-
如果您的页面未包含在 UINavigationController 中,则 NavigationController 属性将为 null
标签: ios xamarin xamarin.ios uinavigationcontroller nullreferenceexception