【问题标题】:Customization tableView自定义tableView
【发布时间】:2012-12-11 11:07:23
【问题描述】:

如何在UITableView 上方添加一个带有 3 个UIButtons 的条形?拜托,我需要例子。我想做like this

【问题讨论】:

    标签: objective-c uitableview custom-controls


    【解决方案1】:

    您可以在情节提要中创建一个包含分段控制器的单元格。

    现在在

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
    

    您可以将该单元格从表中的第一个单元格出列。

    【讨论】:

      【解决方案2】:

      在您的viewDidLoad 中,创建一个背景颜色清晰的UIView

      然后,创建一个UISegmentedControl 并将其作为subview 添加到清晰视图中。

      最后,将清晰的视图设置为表头视图:

      self.tableView.tableHeaderView = myClearView;
      

      【讨论】:

        【解决方案3】:

        Bar 在 iPhone 中被称为分段控件。 要创建它的子类 UIViewControl 类并在顶部添加分段控件,然后在下方添加 UITableView,您可以更好地使用 Xib,或者您可以找到坐标并以编程方式添加这两个控件。

        参考this link

        【讨论】:

          【解决方案4】:

          您可以通过在您的ViewController 中为您的UITableView 实现Header View Section 委托方法来做到这一点 在下面的委托方法中,给出你想要实现的视图的大小

          -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
              return 60.0f;
          }
          

          实现 UISegmentedControl 以获取您的三个按钮并在您的 viewForHeaderInSection 方法中实现它

          -(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
                UISegmentedControl *segmentedControl = [[UISegmentedControl alloc]initWithItems:segments] autorelease];
                segmentedControl.frame =  GRectMake(60, 10, 200, 40);
                ........
                // Do other Stuffs of Segmented Control
                ........
               return segmentedControl;
          }
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2011-08-26
            • 1970-01-01
            • 2018-08-12
            相关资源
            最近更新 更多