我有此错误消息。我正在创建一个Xamarin.ios表视图应用。如果有人可以提前帮助我。
public partial class SessionsViewController : UITableViewController
{
public SessionsViewController (IntPtr handle) : base (handle)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
var sessionManager = SessionsManager.Create();
TableView.Source = new SessionsTableViewSource(sessionManager.Sessions);
}
}
public class SessionsManager
{
private static SessionsManager _instance = null;
public SessionData[] Sessions;
public static SessionsManager Create()
{
if (_instance == null) _instance = new SessionsManager();
return _instance;
}
internal SessionsManager()
{
SessionData[] sessions = new SessionData[5] // receive the error here.{
new Data("1", "Title1", "speaker1", "desc1", DateTime.Today, true),
new Data("2", "Title2", "speaker2", "desc2", DateTime.Today, false),
new Data("3", "Title3", "speaker3", "desc3", DateTime.Today, false),
new Data("4", "Title4", "speaker4", "desc4", DateTime.Today, true),
new Data("5", "Title5", "speaker5", "desc5", DateTime.Today, true)
};
}
我有此错误消息。我正在创建一个Xamarin.ios表视图应用。如果有人可以提前帮助我
答案 0 :(得分:0)
您需要将数组分配给Sessions成员而不是本地变量。
尝试
internal SessionsManager()
{
Sessions = new SessionData[5] {
new Data("1", "Title1", "speaker1", "desc1", DateTime.Today, true),
new Data("2", "Title2", "speaker2", "desc2", DateTime.Today, false),
new Data("3", "Title3", "speaker3", "desc3", DateTime.Today, false),
new Data("4", "Title4", "speaker4", "desc4", DateTime.Today, true),
new Data("5", "Title5", "speaker5", "desc5", DateTime.Today, true)
};
}