Я создал UITableViewCell, но при установке источника UITableView, я получаю NullReferenceException.Xamarin IOS UITableView.Source NullReferenceException
public partial class SessionOverviewViewController : UIViewController
{
public List<BaseSessionController> Sessions;
public SessionOverviewViewController (IntPtr handle) : base (handle)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
tvTable.RegisterClassForCellReuse(typeof(SessionTableViewCell), "SessionCell");
SessionTableViewSource source = new SessionTableViewSource(Sessions);
tvTable.Source = source; //This line throws the Exception
}
}
TableViewSource:
public class SessionTableViewSource : UITableViewSource
{
List<BaseSessionController> TableItems;
string CellIdentifier = "SessionCell";
public SessionTableViewSource(List<BaseSessionController> items)
{
TableItems = items;
}
public override nint RowsInSection(UITableView tableview, nint section)
{
return TableItems.Count;
}
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
SessionTableViewCell cell = (SessionTableViewCell)tableView.DequeueReusableCell(CellIdentifier);
BaseSessionController friend = TableItems[indexPath.Row];
//---- if there are no cells to reuse, create a new one
if (cell == null)
{
//cell = new SessionTableViewCell(new NSString(CellIdentifier), friend.FriendName, new UIImage(NSData.FromArray(friend.FriendPhoto)));
cell = new SessionTableViewCell(new NSString(CellIdentifier), friend);
}
//cell.UpdateCellData(friend.UserName, new UIImage(NSData.FromArray(friend.FriendPhoto)));
return cell;
}
}
И сам сотовый
public partial class SessionTableViewCell : UITableViewCell
{
public BaseSessionController Session;
public SessionTableViewCell (IntPtr handle) : base (handle)
{
}
public SessionTableViewCell(NSString cellId, BaseSessionController session) : base(UITableViewCellStyle.Default, cellId)
{
Session = session;
lblDate.Text = Session.Model.SessionStartTime.ToString("d");
}
}
Надеюсь кто-то может увидеть ошибку, которую я сделал, и может помочь мне с этим.
Заранее спасибо
Вы можете отлаживать и проверять выполнение GetCell или RowsInSection? или "источник" не является нулевым? – Darshana
Кстати, у вас есть ячейка с идентификатором «SessionCell» в раскадровке или xib? Я думаю, что проблема – Darshana
Оба метода не выполняются, и я проверяю 'source'. Это определенно не null, также выход 'UITableView' не является нулевым и т. Д. И да, я устанавливаю идентификатор внутри Storyboard –