ifish/Ifish/YunXinIM/NIMKit/NIMKit/Sections/Session/Object/NIMSessionTableAdapter.m

85 lines
2.5 KiB
Objective-C
Executable File

//
// NIMSessionTableDelegate.m
// NIMKit
//
// Created by chris on 2016/11/7.
// Copyright © 2016年 NetEase. All rights reserved.
//
#import "NIMSessionTableAdapter.h"
#import "NIMMessageModel.h"
#import "NIMMessageCellFactory.h"
#import "UIView+NIM.h"
#import "NIMKitUIConfig.h"
@implementation NIMSessionTableAdapter
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.interactor items].count;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;
id model = [[self.interactor items] objectAtIndex:indexPath.row];
if ([model isKindOfClass:[NIMMessageModel class]]) {
[model calculateContent:tableView.bounds.size.width force:NO];
cell = [NIMMessageCellFactory cellInTable:tableView
forMessageMode:model];
[(NIMMessageCell *)cell setDelegate:self.delegate];
}
else if ([model isKindOfClass:[NIMTimestampModel class]])
{
cell = [NIMMessageCellFactory cellInTable:tableView
forTimeModel:model];
}
else
{
NSAssert(0, @"not support model");
}
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat cellHeight = 0;
id modelInArray = [[self.interactor items] objectAtIndex:indexPath.row];
if ([modelInArray isKindOfClass:[NIMMessageModel class]])
{
NIMMessageModel *model = (NIMMessageModel *)modelInArray;
NSAssert([model respondsToSelector:@selector(contentSize)], @"config must have a cell height value!!!");
[self.interactor checkLayoutConfig:model];
CGSize size = model.contentSize;
UIEdgeInsets contentViewInsets = model.contentViewInsets;
UIEdgeInsets bubbleViewInsets = model.bubbleViewInsets;
cellHeight = size.height + contentViewInsets.top + contentViewInsets.bottom + bubbleViewInsets.top + bubbleViewInsets.bottom;
}
else if ([modelInArray isKindOfClass:[NIMTimestampModel class]])
{
NIMTimestampModel *model = (NIMTimestampModel *)modelInArray;
cellHeight = [model height];
}
else
{
NSAssert(0, @"not support model");
}
return cellHeight;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
[[UIMenuController sharedMenuController] setMenuVisible:NO animated:YES];
}
@end