ios - 关于微信好友列表跳转问题
大家讲道理
大家讲道理 2017-04-18 09:35:53
0
1
609

请问微信中点击通讯录,然后选择一个好友,然后点击发送消息之后,返回的还是主界面?这个功能是怎么实现的呢?看他点击发送消失之后是pop到了通讯录的好友列表,然后在push进去的,我的实现方式是先popToRoot 然后在切换tabbar选中,感觉这样看起来并不丝滑~求助

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(1)
伊谢尔伦

In order to prevent multiple chat interfaces and deep nesting in WeChat and many IM apps, and to unify operating habits, WeChat and many IM apps have a limit of "Every time you enter the chat interface, enter from the conversation list." Several apps I made before are opening the same The same goes for the chat interface.
There is a public method for opening the chat interface, which can be called from any interface. Or define a route for the chat interface.
For example: + [ChatViewController openWithUser:(User *)user];

Take WeChat’s app structure as an example. There is navigation at the top, tabBar at the bottom, and only one conversation list. The logic of opening the chat interface is roughly as follows:

if (currentChatViewController && currentChatViewController.user.userId == user.userId) {
    // 如果这个人的聊天界面已经打开了

    if (conversationListViewController.navigationController.viewControllers.count > 2) {
        // 不在聊天界面:比如在查看资料界面,就返回到聊天界面
        [conversationListViewController popToViewController:currentChatViewController animated:YES];
    }
} else {

    // 退出当前的聊天界面,animated: NO
    if (conversationListViewController.navigationController.viewControllers.count > 1) {
        [conversationListViewController.navigationController popToRootViewControllerAnimated:NO];
    }

    ChatViewController *chatVC = [[ChatViewController alloc] initWithUser:user];

    [conversationListViewController.navigationController pushViewController:chatVC animated:YES];
}

tabBarViewController.selectedIndex = 0;

To get the root controller, session list, and current chat window, you can use global variables or use code to check:

UITabBarController *tabBarViewController = (UITabBarController *)[UIApplication sharedApplication].keyWindow.rootViewController;

UIViewController *conversationListViewController = tabBarViewController.viewControllers.firstObject;

ChatViewController *currentChatViewController =
    (ChatViewController *)(conversationListViewController.navigationController.viewControllers.count > 1 ?
                           conversationListViewController.navigationController.viewControllers[1] : nil);
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template