Search in room: Applied Vector design (ie stole the cells from the RoomViewController to display search results)

This commit is contained in:
manuroe
2015-12-31 16:12:32 +01:00
parent 674aef23f3
commit 8838088876
6 changed files with 162 additions and 3 deletions
@@ -18,13 +18,27 @@
#import "UIViewController+VectorSearch.h"
// Use RoomViewController cells to display results
#import "RoomIncomingAttachmentBubbleCell.h"
#import "RoomIncomingTextMsgBubbleCell.h"
@implementation RoomSearchViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Reuse cells from the RoomViewController to display results
[self.searchTableView registerClass:RoomIncomingTextMsgBubbleCell.class forCellReuseIdentifier:RoomIncomingTextMsgBubbleCell.defaultReuseIdentifier];
[self.searchTableView registerClass:RoomIncomingAttachmentBubbleCell.class forCellReuseIdentifier:RoomIncomingAttachmentBubbleCell.defaultReuseIdentifier];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// Enable the search field at the opening
// Enable the search field at the screen opening
[self showSearch:animated];
}
@@ -45,4 +59,51 @@
[self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - MXKDataSourceDelegate
- (Class<MXKCellRendering>)cellViewClassForCellData:(MXKCellData*)cellData
{
Class cellViewClass = nil;
// Sanity check
if ([cellData conformsToProtocol:@protocol(MXKRoomBubbleCellDataStoring)])
{
id<MXKRoomBubbleCellDataStoring> bubbleData = (id<MXKRoomBubbleCellDataStoring>)cellData;
// Select the suitable table view cell class
if (bubbleData.isAttachmentWithThumbnail)
{
cellViewClass = RoomIncomingAttachmentBubbleCell.class;
}
else
{
cellViewClass = RoomIncomingTextMsgBubbleCell.class;
}
}
return cellViewClass;
}
- (NSString *)cellReuseIdentifierForCellData:(MXKCellData*)cellData
{
Class class = [self cellViewClassForCellData:cellData];
if ([class respondsToSelector:@selector(defaultReuseIdentifier)])
{
return [class defaultReuseIdentifier];
}
return nil;
}
#pragma mark - Override UITableView delegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
// `MXKRoomBubbleTableViewCell` cells displayed by the `RoomViewController`
// do not have line separators.
// The +1 here is for the line separator which is displayed by `RoomSearchViewController`.
return [super tableView:tableView heightForRowAtIndexPath:indexPath] + 1;
}
@end