【问题标题】:How to hide UITableView empty rows,swift如何隐藏 UITableView 空行,swift
【发布时间】:2016-02-13 11:27:14
【问题描述】:

如何从这些行中隐藏 UITableView 的行行,哪些行不使用。比如看截图:

我可以只显示 4 行并隐藏其他未使用的行吗?所以,我只显示 4 行,然后是白屏,而不是现在的行

【问题讨论】:

标签: ios swift uitableview


【解决方案1】:

喜欢在viewDidLoad 上将tableFooterView 框架设置为CGRectZero

override func viewDidLoad() {

super.viewDidLoad()

// set as your tableFooterView frame as CGRectZero it hides the empty rows
self.tableView.tableFooterView = UIView(frame: CGRectZero)

self.tableView.backgroundColor = UIColor.clearColor()

}

【讨论】:

    【解决方案2】:
    //Obj-c code    
        TableName.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
    //Swift code
        tableView.tableFooterView = UIView(frame: .zero)
    

    使用此代码隐藏多余的行。

    将此代码放入 ViewDidLoadViewWillApper

    【讨论】:

      【解决方案3】:
      • Objective-C 中的 sn-ps 在 Swift 中也应该相同

      在你的 viewDidLoad 方法中包含

      self.localTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
      

      在 viewDidLayoutSubViews 中包含

      -(void)viewDidLayoutSubviews
      {
          if ([self.localTableView respondsToSelector:@selector(setSeparatorInset:)]) {
              [self.localTableView setSeparatorInset:UIEdgeInsetsZero];
          }
      
          if ([self.localTableView respondsToSelector:@selector(setLayoutMargins:)]) {
              [self.localTableView setLayoutMargins:UIEdgeInsetsZero];
          }
      }
      

      在tableView willDisplyCell 委托方法中包含

      -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
      {
          if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
              [cell setSeparatorInset:UIEdgeInsetsZero];
          }
      
          if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
              [cell setLayoutMargins:UIEdgeInsetsZero];
          }
      }
      

      这里 localTableView 是从情节提要中取出的插座

      【讨论】:

        【解决方案4】:

        // 斯威夫特 3

        override func viewDidLoad() {
            super.viewDidLoad()
        
            tableView.tableFooterView = UIView(frame: .zero) }
        

        【讨论】:

          猜你喜欢
          • 2020-07-01
          • 1970-01-01
          • 2014-08-19
          • 2011-05-11
          • 1970-01-01
          • 2012-07-28
          • 2019-10-05
          • 2017-12-09
          • 1970-01-01
          相关资源
          最近更新 更多