Reputation: 4360
I am trying to implement adding recipients to TTMessageController based on the example from TTCatalog. Everything works fine until I enter search controller - I can search and get results, but nothing happens when I select items. I tried to set delegates, but none works.
- (void)loadView {
[super loadView];
TTTableViewController* searchController = [[TTTableViewController alloc] init];
searchController.dataSource = [[FriendsDataSource alloc] initWithApi:self.appDelegate.api];
searchController.variableHeightRows=YES;
self.searchViewController = searchController;
self.tableView.tableHeaderView = _searchController.searchBar;
}
In TTCatalog, items in search have an URL directing to google - that's not very helpful ;)
Upvotes: 2
Views: 726
Reputation: 4360
OK, I've found the answer :)
One line was missing from the code above. I had a feeling I should set the delegate, but didn't know where:
- (void)loadView {
[super loadView];
TTTableViewController* searchController = [[TTTableViewController alloc] init];
searchController.dataSource = [[FriendsDataSource alloc] initWithApi:self.appDelegate.api];
self.searchViewController = searchController;
_searchController.searchResultsTableView.delegate=self;
self.tableView.tableHeaderView = _searchController.searchBar;
}
Then it as enough to add this to allow variable heights:
- (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];
}
And this to handle selection:
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
TTTableImageItemCell *cell = (TTTableImageItemCell *) [tableView cellForRowAtIndexPath:indexPath];
TTTableImageItem *object = [cell object];
[_delegate MessageAddRecipient:self didSelectObject:object];
}
Upvotes: 2