【发布时间】:2017-05-01 01:35:35
【问题描述】:
我正在尝试构建 iOS 应用程序,其中一个视图控制器正在调用(推送)另一个视图控制器。在第二个视图控制器中,我有静态 TableViewController 与 1 个部分和 2 个静态单元格。
每当我访问单元格的元素时,代码都会引发异常。
View Controller 2 通过以下代码推送:
var destinationController = new EditAccountTableViewController(accounts[indexPath.Row]);
parentController.NavigationController.PushViewController(destinationController, true);`
EditAccountTablewViewController 类:
public partial class EditAccountTableViewController : UITableViewController
{
private Account account;
public EditAccountTableViewController()
{
var loc = NSBundle.MainBundle.LocalizedString("New", "");
var loc2 = NSBundle.MainBundle.LocalizedString("Account", "");
Title = $"{loc} {loc2}";
this.account = new Account();
AccountNameCell.DetailTextLabel.Text = account.Name;
AccountDescriptionCell.DetailTextLabel.Text = account.Description;
}
public EditAccountTableViewController(Account account)
{
var loc = NSBundle.MainBundle.LocalizedString("Account", "");
Title = $"{loc}";
this.account = account;
AccountNameCell.DetailTextLabel.Text = account.Name;
AccountDescriptionCell.DetailTextLabel.Text = account.Description;
}
partial void SaveAccountButton_Activated(UIBarButtonItem sender)
{
if (account.Name != string.Empty)
{
Database.Instance.DataAccess.SaveModelItem<Account>(account);
}
}
}
AccountNameCell 和 AccountDescriptionCell 是单元格名称。单元格在此处的情节提要中创建:
我很清楚,该异常是由AccountNameCell 引起的,即null。我不明白为什么是null,也不明白如何解决。
感谢您的帮助。
【问题讨论】:
标签: xcode uitableview xamarin uiviewcontroller tableview