I couldn't get variableHeightRows to work on a search v开发者_如何学Pythoniew controller.
TTTableViewController* searchController = [[TTTableViewController alloc] init];
searchController.dataSource = [[[SomeDataSource alloc] init] autorelease];
searchController.variableHeightRows = YES; // this doesn't affect the table
self.searchViewController = searchController;
[searchController release];
self.tableView.tableHeaderView = _searchController.searchBar;
_searchController.pausesBeforeSearching = YES;
[_searchController setSearchResultsDelegate:self];
It always show the rows in the default height. On my regular table view with the same datasource, the height of the rows is set to the custom one I supply in + (CGFloat)tableView:(UITableView*)tableView rowHeightForObject:(id)object
, but specifically not on the search controller.
Am I doing it wrong?
After deep investigation...
I set the delegate of the search controller to the same class ([_searchController setSearchResultsDelegate:self];
), something which prevented from a TTTableViewVarHeightDelegate delegate to be created, therefore, the custom heightForRowAtIndexPath wasn't called. I added:
- (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath {
id<TTTableViewDataSource> dataSource = (id<TTTableViewDataSource>)tableView.dataSource;
id object = [dataSource tableView:tableView objectForRowAtIndexPath:indexPath];
Class cls = [dataSource tableView:tableView cellClassForObject:object];
return [cls tableView:tableView rowHeightForObject:object];
}
to the TTTableViewController class (source of TTTableViewVarHeightDelegate) and it worked.
精彩评论