2011-10-26 34 views
1

我想查看附件按鈕,如selectall或deselectall。
cell.Accessory = UITableViewCellAccessory.None; 我想要一個按鈕示例:「全選」 當用戶觸摸此按鈕時,每個單元的附件都應勾選。 或者我想要「重置」按鈕。如果用戶觸摸此按鈕,則每個複選標記消失,並且Cell的附件不存在。如何通過「全選」和「全部取消」按鈕獲得UITableView

+0

你能說得更具描述性嗎?無法理解你的問題。 – 0x8badf00d

+0

我很抱歉,但我不明白你的問題。你可以編輯它提供更多的細節?特別是按鈕和UITableViewCellAccessory之間的聯繫。後者記錄在這裏:http://developer.apple.com/library/IOS/#documentation/UIKit/Reference/UITableViewCell_Class/Reference/Reference.html#//apple_ref/doc/c_ref/UITableViewCellAccessoryNone – poupou

回答

4

正如你可能發現使用UITableView有點複雜。不過,MonoTouch提供了一個名爲MonoTouch.Dialog的精彩庫,使事情變得更加簡單。

下面的示例代碼是使用MonoTouch.Dialog來回答你的問題(盡我所知,讓我知道如果我的答案不符合你想要的)。

UIBarButtonItem [] selection_buttons; 

    void Process (IList<Element> list, bool value) 
    { 
     foreach (Element e in list) { 
      CheckboxElement cb = e as CheckboxElement; 
      if (cb == null) 
       continue; 
      cb.Value = value; 
      cb.GetImmediateRootElement().Reload (cb, UITableViewRowAnimation.None); 
     } 
    } 

    void Test() 
    { 
     Section s = new Section ("Select items"); 
     for (int i = 0; i < 10; i++) 
      s.Add (new CheckboxElement (i.ToString())); 
     var root = new RootElement (String.Empty); 
     root.Add (s); 

     var dv = new DialogViewController (root, true); 

     // keep buttons in a field, not a local variable, to ensure it won't be GC'ed away 
     if (selection_buttons == null) { 
      selection_buttons = new UIBarButtonItem [] { 
       new UIBarButtonItem ("Deselect All", UIBarButtonItemStyle.Plain, delegate { 
        Process (s.Elements, false); 
       }), 
       new UIBarButtonItem ("Select All", UIBarButtonItemStyle.Plain, delegate { 
        Process (s.Elements, true); 
       }) 
      }; 
     } 

     dv.NavigationItem.SetRightBarButtonItems (selection_buttons, true); 
     NavigationController.PushViewController (dv, true);    
    } 

與MonoTouch(和MonoTouch.Dialog)玩得開心!

+0

順便說一句:是新的Monotouch中綁定的SDK 5的靜態表格東西,還是您希望人們使用Monotouch.Dialog? – Krumelur

+0

@Krumelur它應該在那裏 - 缺少的東西就是一個錯誤。我們試圖提供選擇,包括在可能的情況下提供所有iOS功能**和**更簡單的API(並且它可能超過UITableView ;-)) – poupou

2

您可以從developer.apple.com結帳this demo。希望它能幫助你。

相關問題