Android 使用UINib加速表视图单元格加载

Android 使用UINib加速表视图单元格加载,android,ios,iphone,xmpp,chat,Android,Ios,Iphone,Xmpp,Chat,我正在开发iPhone聊天应用程序 运行应用程序后,当我点击任何聊天室时,打开聊天室时存在1~2秒的延迟 此延迟仅在运行后第一次出现 回到聊天室列表后,当我再次单击任何聊天室时,都没有存在延迟 当我看到whatsapp时,没有任何延迟,一点击聊天室就立即打开聊天室 现在,在ViewWillDisplay上,当前聊天室消息已经从DB中获取,我调用了UITableView的reloadData 有人知道为什么会有延迟吗 或者有谁知道一个完美的架构可以毫不延迟地打开聊天室 请给我一些建议,谢谢 聊天室

我正在开发iPhone聊天应用程序

运行应用程序后,当我点击任何聊天室时,打开聊天室时存在1~2秒的延迟

此延迟仅在运行后第一次出现

回到聊天室列表后,当我再次单击任何聊天室时,都没有存在延迟

当我看到whatsapp时,没有任何延迟,一点击聊天室就立即打开聊天室

现在,在ViewWillDisplay上,当前聊天室消息已经从DB中获取,我调用了UITableView的reloadData

有人知道为什么会有延迟吗

或者有谁知道一个完美的架构可以毫不延迟地打开聊天室

请给我一些建议,谢谢

聊天室虚拟控制器类

- (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];
            });
...
}
- (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;
}
ChatBoardViewController类

- (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];
            });
...
}
- (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;
}

打开聊天室是什么意思?您的意思是加载某些
UITableView
的内容,还是导航到包含它的视图控制器?如果是后者,则问题不在于加载单元格。发布一些代码,因为如果仅仅基于模糊的描述很难说出原因。你也可以使用时间分析器工具来确定延迟可能发生的位置。谢谢你的评论,可能与我用一些代码更新了帖子有关。