I'm implementing a TTTableViewController with a searchViewController part, and I'm running into issues when displaying the results of the search in the search's TableView.
If I add TTTableTextItems to the datasource items
property, it works fine, but if I try to add a TTTableCaptionItem or a TTTableImageItem or any custom cell I've created, the rendering is messed up.
Can anyone confirm that it's possible to use custom table cells in a searchViewController and perhaps point me in the right direction for how to make it work?
I've attached 3 screen shot to show what's working and what's not working.
No. 1: Works with this code:
[self.items addObject:[TTTableTextItem itemWithText:[item objectForKey:@"title"]]];
No 2. Breaks the layout with this code:
[self.items addObject:[TTTableCaptionItem itemWithText:[item objectForKey:@"title"]
caption:[item objectForKey:@"excerpt"]]];
No. 3 Also breaks the layout with this code:
[self.items addObject:[TTTableImageItem itemWithText:[item objectForKey:@"title"]
开发者_Python百科 imageURL:[item objectForKey:@"thumbnail"]]];
OK, I figured it out. The key is setting the the variableHeightRows
property to YES
in the TTTableViewController that you're using as the search controller. Below is the code I've used.
TTTableViewController* searchController = [[[TTTableViewController alloc] init] autorelease];
searchController.dataSource = [[[MagazineSearchDataSource alloc] init] autorelease];
searchController.variableHeightRows = YES;
self.searchViewController = searchController;
self.tableView.tableHeaderView = _searchController.searchBar;
精彩评论