我想創建建議給UISearchBar,所以我添加了UITableView,並且我想通過內容更改UITableView的高度。iOS - 動態更改uitableview的高度
當我得到的數據我打電話:
[self.searchTableView reloadData];
和- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
我試圖調整大小的tableView:(20是1行的高度)
CGRect bounds = [tableView bounds];
NSLog(@"%f",tableView.contentSize.height);
[tableView setBounds:CGRectMake(bounds.origin.x,
bounds.origin.y,
bounds.size.width,
20 * [self.suggestionData count])];
/*
CGRect frame = self.searchTableView.frame;;
frame.size.height = 20 * [self.suggestionData count];
self.searchTableView.frame = frame;
*/
我試過的tableView。 contentSize.height也是如此,但它沒有工作。也許有必要改變故事板或我的東西,當我試圖找到解決方案,我改變了一些錯誤。我只是得到了tableview的高度,就像我在storyboard中設置的一樣。謝謝
你想通過改變UITableView的高度來實現什麼? –
更改桌子的高度。該表附加到searchBar,並作爲該searchBar(自動完成功能)的建議。 –
爲什麼不直接使用UISearchDisplayController? –