【问题标题】:UITableView Static Cells - How to limit rows displayed?UITableView 静态单元格 - 如何限制显示的行数?
【发布时间】:2012-04-05 01:36:27
【问题描述】:

在 iOS 5 上

我有一个 UITableViewController 设置为静态单元格。我只需要 3 行,每行都将填充内容。所以我放了3个UITableViewCell。一切正常,但是当我运行应用程序时,它总是显示超过 3 行。其余行是空行。我怎样才能只显示我打算显示的 3 行。

我应该使用分组样式并自定义外观吗?

【问题讨论】:

    标签: uitableview static-content


    【解决方案1】:

    将 footerView 设置为空视图。

    self.tableView.tableFooterView = [UIView new].
    

    这适用于动态单元格。也应该适用于静态单元格。

    【讨论】:

      【解决方案2】:

      在你的 UITableViewController 中实现这两个方法:

      - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
      {
          if (section == tableView.numberOfSections - 1) {
              return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
          }
          return nil;
      }
      
      
      - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
      {
          if (section == tableView.numberOfSections - 1) {
              return 1;
          }
          return 0;
      }
      

      其实这些代码是在告诉tableview你不用再为我渲染分隔线了,这样看起来空单元格就不会显示了(其实空单元格也不能被选中)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多