Ios 使uitableview单元格高度由搜索时单元格内容的自动高度决定
我有一个UITable视图和一个搜索栏,问题是如果它处于正常状态,非搜索模式,每行的高度是静态的Ios 使uitableview单元格高度由搜索时单元格内容的自动高度决定,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我有一个UITable视图和一个搜索栏,问题是如果它处于正常状态,非搜索模式,每行的高度是静态的 -(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 78.0; } 当状态变为搜索时,单元格高度应该由实际内容决定,那么我如何告诉表视图这一点呢 我试着这样做: - (void)searchBar:(UISearchBar *)searc
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 78.0;
}
当状态变为搜索时,单元格高度应该由实际内容决定,那么我如何告诉表视图这一点呢
我试着这样做:
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
NSLog(@"Text change - %d",self.searching);
//Remove all objects first.
[self.searchResult removeAllObjects];
if([searchText length] != 0) {
self.searching = YES;
[self searchTableList];
self.tableView.rowHeight = UITableViewAutomaticDimension;
// try to do it with this, not working
[self.tableView reloadData];
}
else {
self.searching = NO;
}
[self.tableView reloadData];
}
但它不起作用
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewAutomaticDimension;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewAutomaticDimension;//78.0;
}
对行高尝试此操作第一次估计的行高为rowatindexpath获取单元格高度,而不是rowatindexpath设置的高度UITableViewAutomaticDimension是您的估计高度UITableViewAutomaticDimension是您的单元格高度,不管它是什么