【问题标题】:Monotouch.Dialog RootElement that opens a UIViewController and Passing in DataMonotouch.Dialog RootElement 打开 UIViewController 并传入数据
【发布时间】:2012-05-01 18:35:16
【问题描述】:

当用户单击 RootElement 时,是否有正确的方法来使用 Monotouch.Dialog (iOs) 并调用 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; 
}

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

【问题讨论】:

    标签: xamarin.ios monotouch.dialog


    【解决方案1】:

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

    将你的 foreach 循环改为如下所示:

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

    【讨论】:

    • 工作就像一个魅力......谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-27
    相关资源
    最近更新 更多