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
Simple you can use this..
tableView.tableFooterView = [UIView new];
For swift 2.x xCode 7 :
override func viewDidLoad() {
super.viewDidLoad()
print("∙ \(NSStringFromClass(self.dynamicType))")
...
self.tableView.tableFooterView = UIView()
}
- (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] ;
}
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.
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'.
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)
}