Monotouch Dialog Section element, Elements property not working properly

StavrosMenegosStavrosMenegos Stavros MenegosGRMember, Beta
edited October 2012 in iOS

Hi, I am using the following pice of code to instantiate a dialogviewcontroller:

var sec = new Section("Category AAAA", "End of Section A") ;

sec.Elements = new List<Element>() { new EntryElement("Hello", "name", "5555") };
RootElement re = new RootElement ("Hello") {
    sec
};

DialogViewController dvc = new DialogViewController (UITableViewStyle.Plain, re, true);
NavigationController.PushViewController (dvc, true);

and I get an exception:

System.NullReferenceException: A null value was found where an object instance was required.
  at MonoTouch.Dialog.EntryElement.ComputeEntryPosition (MonoTouch.UIKit.UITableView tv, MonoTouch.UIKit.UITableViewCell cell) [0x0000c] in /Developer/MonoTouch/Source/MonoTouch.Dialog/MonoTouch.Dialog/Elements.cs:1488
  at MonoTouch.Dialog.EntryElement.GetCell (MonoTouch.UIKit.UITableView tv) [0x00057] in /Developer/MonoTouch/Source/MonoTouch.Dialog/MonoTouch.Dialog/Elements.cs:1540
  at MonoTouch.Dialog.DialogViewController+Source.GetCell (MonoTouch.UIKit.UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath) [0x00029] in /Developer/MonoTouch/Source/MonoTouch.Dialog/MonoTouch.Dialog/DialogViewController.cs:340
  at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
  at ESQuestion.Application.Main (System.String[] args) [0x00000] in /Users/sme/Documents/Developement/ESQuestion/ESQuestion/Main.cs:18

Should I use the following code, it works as it should:

var sec = new Section("Category AAAA", "End of Section A") {new EntryElement("Hello", "name", "5555") };
RootElement re = new RootElement ("Hello") {
    sec
};

DialogViewController dvc = new DialogViewController (UITableViewStyle.Plain, re, true);
NavigationController.PushViewController (dvc, true);`

Posts

  • Joseph_AndersonJoseph_Anderson Joseph Anderson USMember

    Hi,

    Please use your second code sample. It seems like the elements property is null in your first example.

  • NicWiseNicWise Nic Wise NZMember, Insider ✭✭✭

    You can also use

    sec.Add(new Element....);

  • StavrosMenegosStavrosMenegos Stavros Menegos GRMember, Beta
    edited October 2012

    It seems that there is a problem in using the Elements Property by assignment. I also tried the naive approach:

    var sec = new Section("Category AAAA", "End of Section A") {
        from x in listofelements
        select x
    }
    
Sign In or Register to comment.