Hide empty cells in UITableView

后端 未结 7 826
春和景丽
春和景丽 2021-01-11 12:47

I have a searchable tableview, but would like to only display the number of cells that are returned once a user starts a search. For instance, if a user types in a charecter

相关标签:
7条回答
  • 2021-01-11 13:14

    Simple you can use this..

    tableView.tableFooterView = [UIView new];
    
    0 讨论(0)
  • 2021-01-11 13:15

    For swift 2.x xCode 7 :

    override func viewDidLoad() {
            super.viewDidLoad()
            print("∙ \(NSStringFromClass(self.dynamicType))")
            ...
            self.tableView.tableFooterView = UIView()
    }
    
    0 讨论(0)
  • 2021-01-11 13:18
    - (void) viewDidLoad
    {
      [super viewDidLoad];
     *// self.tableView.tableFooterView = [[[UIView alloc] init] autorelease];*   
      *//Since memory management is controlled by ARC now, so ignore autorelease*
      self.tableView.tableFooterView = [[UIView alloc] init] ;
    }
    
    0 讨论(0)
  • 2021-01-11 13:21

    Change your implementation of tableView:numberOfRowsInSection: in your data source to return the number of search results instead of the total number of items. Then populate those cells with the search results instead of with the rest of the data.

    0 讨论(0)
  • 2021-01-11 13:22

    Set the tableFooterView to some dummy view ([[UIView new] autorelease] will work fine). This prompts the UITableView to show the footer (which will have zero size) in place of the empty 'cells'.

    0 讨论(0)
  • 2021-01-11 13:22

    Hiding an empty cells in Swift

    Swift 3 Edition

     override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
    
        self.tableView.tableFooterView = UIView(frame: CGRect.zero)
    }
    

    Swift 2 Edition

     override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
    
        self.tableView.tableFooterView = UIView(frame: CGRectZero)
    }
    
    0 讨论(0)
提交回复
热议问题