iPhone:如何创建可扩展的表视图?

时间:2011-09-27 11:36:08

标签: iphone objective-c cocoa-touch uitableview ios4

我想创建可扩展的表格视图。

我发现一个link与我想要的相同。

enter image description here

但是我想创建自己的表视图(不想实现这个github代码)。

如何实现此类功能?

2 个答案:

答案 0 :(得分:1)

看到这个很好的教程: Table View Animations and Gestures

演示如何使用动画更新来打开和关闭表格视图的各个部分以供查看,其中每个部分代表一个游戏,每行包含游戏的引用。它还使用手势识别器来响应用户输入:* UITapGestureRecognizer允许点击节标题以扩展该节; * UIPinchGestureRecognizer允许动态更改表视图行的高度;和*一个UILongPressGestureRecognizer,允许在表视图单元格上按住并发起引用的电子邮件。

答案 1 :(得分: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)expand:(id)sender;

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

      了解更多详情enter link description here