2011-09-27 62 views

回答

1

看到這個漂亮的教程: Table View Animations and Gestures

演示瞭如何使用動畫更新來打開和查看,其中每個部分代表一個玩表視圖的閉部分,每一行都包含來自劇中報價。它還使用手勢識別器來響應用戶輸入:*一個UITapGestureRecognizer允許點擊節頭以擴展節; * UIPinchGestureRecognizer允許動態改變表格視圖行的高度; * UILongPressGestureRecognizer允許按住表格視圖單元以啓動報價電子郵件。

+0

這正是不是教程,只是一個示例代碼 – ilhnctn

0

我遇到了類似的功能,全力打造成爲一個粗略的算法是:

  1. 實施uitableviewdelgate和uitableviewdatasource協議

  2. 創建一個全局變量expandedSectionIndex = -1;

    = -1表示全部摺疊。

    = 0表示expandedSectionIndex。

    //the following protocol definitions will take care of which section is to be expanded. 
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
        { 
         if(expandedSectionIndex == section) 
          return [self.dataArray[section] count]; 
         else 
          return 0; 
        } 
    
        - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
        { 
        if(self.dataArray) 
          return [self.dataArray count]; 
        } 
    

    在定義自定義首部的觀點 - 的tableView:viewForHeaderInSection:具有幀等效

    • 按鈕到頭視圖幀
    • 設定按鈕標籤屬性與節號值。
    • 將所有按鈕與選擇器關聯 - (void)展開:(id)sender;

      - (void)expand:(id) sender 
      { 
          expandedSectionIndex = [sender tag]; 
          [self.tableView reload]; 
      } 
      

      更多細節enter link description here