OC实现一个简单的聊天列表

实现一个简单的聊天列表

A simple chat list tableView .

自定义简单的聊天界面

效果展示iPad

GitHub set up-w250

实现思路

简单的聊天界面,用UITableView可以展示和刷新聊天数据的cell,自定义显示聊天信息的cell,更新数据源刷新显示即可。

实现过程

tableView:创建用来显示聊天的tableView

self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
self.tableView.dataSource = self;
self.tableView.delegate = self;
[self.view addSubview:self.tableView];

ChatViewCell:自定义cell,cell即每条聊天信息的显示

@interface ChatViewCell : UITableViewCell

@property (nonatomic, strong) UILabel *nickNameLable;//昵称Label
@property (nonatomic, strong) UIImageView *headerImgView;//头像UIImageView
@property (nonatomic, strong) UIButton *contentBtn;//显示聊天内容的button

- (void)setMsg:(ChatModel *)model;//给cell赋值的方法

@end

ChatModel:提供数据模型

///数据源模型
@interface ChatModel : NSObject

@property (nonatomic, assign) CGFloat cellHeight;//cell行高

@property (nonatomic, copy) NSString *nickName;//昵称
@property (nonatomic, copy) NSString *headerUrl;//头像url
@property (nonatomic, copy) NSString *msg;//消息
@property (nonatomic, assign) MSGTypeBy msgTypeBy;

@property (nonatomic, strong, nonnull) ChatFrameModel *frameModel;//坐标信息model,非空的

- (void)setattributesWithDict:(NSDictionary *)dict;//model赋值方法

@end

///坐标数据模型
@interface ChatFrameModel : NSObject

@property (nonatomic, assign) CGRect nickNameLableFrame;
@property (nonatomic, assign) CGRect headerImgViewFrame;
@property (nonatomic, assign) CGRect contentBtnFrame;

@end

每一条聊天信息都以一个ChatModel的模型传到对应的cell里面,在cell里面显示信息即可。在ChatModel里面我们不光是做了一些基础属性的赋值操作,还进行了frame的计算,cell高度的计算等。

最后

整个实现过程的思路还是挺简单的,简约,简约,简约,其他的功能可以扩展。

demo下载地址

猜你喜欢

转载自blog.csdn.net/morris_/article/details/80251085