0

I have the following code:

Section _section = new Section ("Test");


foreach (ExampleData data in Example.data) {

     MessageElement Item = new MessageElement (){

    Sender = data.Name,
    Subject = data.Value,
    Body = data.Description,
    Date = data.Modified
         } ;

          _section.Add(Item);


            var root = new RootElement("Item Expanded"){

                new Section ("test2"){
                    new StringElement("Field Name", data.FieldName),
                    new StringElement("Value", data.Value),
                    new StringElement("Description", data.Description)
                }


            } ;
            _section.Add(root);

        } ;



        var _rootElement = new RootElement ("Items") {
            _section
        } ;

I would like this to work in such a way that when a Message Element is tapped it shows the section with ("test2") that has the same data (e.g. the data was added during the same run of the loop.) I realize this will not happen currently, as it seems the Message Element requires an Action delegate to do anything on a tap event, plus I'm adding everything to the same section. However, is there any way to replicate the behavior of multiple nested root elements and sections with a Message Element? If I create new pages/screens and try to transition that way, it rests the navigation controller and I lose the use of the back button, even if "push" is set to true.

servarevitas3
  • 483
  • 1
  • 6
  • 23
  • Did you try adding the section dynamically to the root element on tap/click event? Also, this is not the iOS way. It is preferred "pushing" rather than expanding. – Candide Dec 04 '12 at 14:48
  • I was speaking of nesting like in the example code here: https://github.com/migueldeicaza/MonoTouch.Dialog#monotouchdialog Is that considered bad practice? – servarevitas3 Dec 04 '12 at 14:53
  • I think I misunderstood you, and I'm still not clear what you want to happen. – Candide Dec 04 '12 at 15:10

1 Answers1

2

Not sure what you want exactly. Replace your "Item Expanded" root element code with this to push a dialog viewcontoller on the navigation stack with a backbutton. Ofcourse your DialogViewcontroller should be in a UINavigation controller in the first place for this to work

        Item.Tapped += delegate(DialogViewController arg1, UITableView arg2, NSIndexPath arg3) 
        {
            var newDialogVC = new DialogViewController(
                UITableViewStyle.Grouped,
                new RootElement("Item Expanded")
                {
                    new Section ("test2"){
                    new StringElement("Field Name", "test"),
                    new StringElement("Value", "test"),
                    new StringElement("Description", "test")
                }
                                                }
                , true);

            arg1.NavigationController.PushViewController(newDialogVC,true);
        };
svn
  • 1,235
  • 10
  • 22
  • Spoke too soon. The last element in the loop ends up added to each String Element in the delegate for each Message Element. It's like they're being passed ByRef instead of ByVal – servarevitas3 Dec 04 '12 at 15:57
  • you should probably change your loop to a for loop and then reference the data in the delegate by index Example.Data[i].FieldName. This is because the delegate is only executed when you tap the message. At that time the foreach ,oop is already done and data is the last element – svn Dec 04 '12 at 16:02
  • That results in an index out of range exception when the item is actually tapped on. – servarevitas3 Dec 04 '12 at 16:15
  • Its hard to solve without knowing the context and seeing the code. You should store and reference the data array/collection as a class variable (not a local variable). By the time to delegate executes the viewdidload is already done. – svn Dec 04 '12 at 16:19
  • Got it by using Example.Data[arg3.Row].FieldName Thanks again! – servarevitas3 Dec 04 '12 at 16:20