android - 使用 UINib 加快表格视图单元格的加载速度
问题描述
我正在开发 iPhone 聊天应用程序。
运行应用程序后,当我单击任何聊天室时,打开聊天室时会出现 1~2 秒的延迟。
这种延迟只会在运行后第一次出现。
回到聊天室列表后,当我再次点击任何聊天室时,没有延迟。
当我看到whatsapp时,没有任何延迟,一点击聊天室就立即打开了聊天室。
现在,在 viewWillAppear 上,当前聊天室消息已从 DB 中获取,我调用了 UITableView 的 reloadData。
任何人都知道为什么存在延迟?
或者任何人都知道完美的架构可以毫不拖延地打开聊天室?
请指教,谢谢。
ChatRoomsViewController 类
- (void)viewDidLoad {
...
self.chat_board = [[ChatBoardViewController alloc] initWithNibName:@"ChatBoardViewController" bundle:nil];
UINib *nib = [UINib nibWithNibName:@"ChatBoardRightCell" bundle:nil];
[_chat_board.board_table registerNib:nib forCellReuseIdentifier:@"ChatBoardRightCell"];
nib = [UINib nibWithNibName:@"ChatBoardLeftCell" bundle:nil];
[_chat_board.board_table registerNib:nib forCellReuseIdentifier:@"ChatBoardLeftCell"];
...
}
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
...
dispatch_async(dispatch_get_main_queue(), ^{
OrientationEnabledNavigation *navcon = (OrientationEnabledNavigation*)self.tabBarController.selectedViewController;
[navcon pushViewController:_chat_board animated:isAnim];
});
...
}
ChatBoardViewController 类
- (void)viewWillAppear:(BOOL)animated {
...
[time_sections removeAllObjects];
_messageTotalCount = [[ChatStorage sharedStorage] getMessageCount:chat_id];
if (self.isLoadAll) {
self.showingCount = _messageTotalCount;
[time_sections addObjectsFromArray: [[ChatStorage sharedStorage] getTimeGroups:chat_id count:_messageTotalCount]];
}else{
[time_sections addObjectsFromArray: [[ChatStorage sharedStorage] getTimeGroups:chat_id count:self.showingCount]];
}
[self reloadData];
...
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
...
NSString *identifier = is_owner ? @"ChatBoardRightCell" : @"ChatBoardLeftCell";
ChatBoardCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
NSString * parsed_msg = [record objectForKey:@"parsed_message"];
NSDictionary * decoded = [[ChatStorage sharedStorage] decodeStringToDictionary:parsed_msg];
[cell setText:decoded editMode:_edit_mode];
...
return cell;
}
解决方案
推荐阅读
- html - 这种应用内容安全策略的方法可以吗?
- google-app-engine - 将 ASP.NET Core 2.1 应用程序部署到 Google Cloud App Engine 错误:字符范围错误
- cypress - cypress.io 和隐藏元素在 DOM 中不存在
- java - 如何吐司验证错误消息显示没有选择微调器中的项目?
- java - Java从被调用方法退出while循环
- angular - Angular 在部署后无法路由到延迟加载的模块
- c# - 在 IIS 中使用 Crystal Reports 部署应用程序
- javascript - 在多步模式中显示第一个表单
- html - Foundation 6 CSS 复选框样式
- android - Google Play 开发者控制台上的 Apk 上传不起作用