2012-05-01 26 views
0

当用户单击RootElement时,是否有正确的方法来使用Monotouch.Dialog(iOs)并调用UIViewController?我正在建立一个基于数组的数据页面,点击时我想打开这个自定义视图并传入数组元素..类似这样的东西(不起作用)。任何帮助表示赞赏。Monotouch.Dialog RootElement打开UIViewController并传入数据

RootElement CreateMenuCategory(JToken menucat) { 

    RootElement MenuCategory = new RootElement(menucat["menucategoryname"].Value<String>()); 

    RootElement root_element; 
    Section section = new Section(); 
    foreach(JToken menuitem in menucat["menuitems"]) { 
    root_element = new RootElement(menuitem["menuitemname"].Value<String>(), (RootElement e) => { 
     return _menuitemView.LoadMenuItem(menuitem); // menuitem on view is always the same 
    }); 

    section.Add (root_element); 

    } 

MenuCategory.Add (section); 

return MenuCategory; 
} 

该代码不起作用,因为委托始终每次都传递相同的元素。

回答

1

这仅仅是lambda函数如何捕获“menuitem”变量的副作用。

更改您的foreach循环看起来像这个:

foreach (JToken iteratorMenuitem in menucat ["menuitems"]){ 
    var menuitem = iteratorMenuitem; 
    //.. the rest 
+0

工作就像一个魅力..谢谢。 – lucuma

相关问题