2012-05-01 28 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

相關問題