最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[已规避]swift关闭ViewController后显示新页面结果导航栏标题重叠错乱

Swift crifan 3071浏览 0评论

代码:

                    //close current vc
                    //close parent selection person vc
                    //and jump to newly created group/topic conversation
                    dispatch_async(dispatch_get_main_queue(), { () -> Void in
                        //close current view: CreateGroupTopicViewController
//                        self.navigationController?.popViewControllerAnimated(true)
                        let callerVc0 = self.navigationController?.popViewControllerAnimated(true)
                        print("callerVc0=\(callerVc0)")
                        //close caller view: SelectPersonViewController
//                        self.navigationController?.popViewControllerAnimated(true)
                        let callerVc1 = self.navigationController?.popViewControllerAnimated(true)
                        print("callerVc1=\(callerVc1)")
                        //jump to newly created group/topic conversation
                        let groupTopicMsgTVC:MessageTableViewController = gConversationTVC.getMsgTVCFromContactId(newGroupTopicId)
                        self.showViewController(groupTopicMsgTVC, sender: groupTopicMsgTVC)
                    })

结果显示界面错乱了:

改为:

                        //self.showViewController(groupTopicMsgTVC, sender: groupTopicMsgTVC)
                        gConversationTVC.showViewController(groupTopicMsgTVC, sender: groupTopicMsgTVC)

问题依旧。

swift navigation title messy

swift navigation title overlap

swift – Changing navigation title programmatically – Stack Overflow

Fixing the iOS 7 Navigation Bar Overlap Problem

objective c – iOS 7 Status Bar Collides With NavigationBar – Stack Overflow

iphone – iOS 7 status bar overlapping UI – Stack Overflow

ios – UINavigationController overlapping the ViewController content – Stack Overflow

swift navigation title left right overlap

swift – overlapping UINavbar left item – Stack Overflow

swift navigation controller pop but item left

换成:

                        if let caller0VC = getCallerViewController(self){
                            print("caller0VC=\(caller0VC)")
                            //caller0VC=<JianDao.SelectPersonViewController: 0x7aed2210>
                            print("caller0VC.navigationController=\(caller0VC.navigationController)")
                            //caller0VC.navigationController=Optional(<UINavigationController: 0x7bbe7e00>)
                            caller0VC.navigationController?.popViewControllerAnimated(true)
                           
                            if let caller1VC = getCallerViewController(caller0VC) {
                                print("caller1VC=\(caller1VC)")
                                //caller1VC=<JianDao.ConversationManageViewController: 0x7af796c0>
                                print("caller1VC.navigationController=\(caller1VC.navigationController)")
                                //caller1VC.navigationController=Optional(<UINavigationController: 0x7bbe7e00>)
                                caller1VC.navigationController?.popViewControllerAnimated(true)
                               
                                //                        if let caller2VC = getCallerViewController(caller1VC) {
                                //                            print("caller2VC=\(caller2VC)")
                                //                            //caller2VC=<JianDao.ConversationManageViewController: 0x7af796c0>
                                //                            caller2VC.navigationController?.popViewControllerAnimated(true)
                                //                        }
                            }
                        }

结果还是不行。

swift   popViewControllerAnimated not work

ios – Can’t unwrap Optional on popViewControllerAnimated – Stack Overflow

ios – Popping ViewController on Swift – Stack Overflow

ios – self.navigationController?.popViewControllerAnimated from UIAlertController – Stack Overflow

ios – Navigation controller popViewControllerAnimated : yes is not working as expected – Stack Overflow

看到navigation controller中有个:

popToRootViewControllerAnimated

所以去试试:

                self.navigationController?.popToRootViewControllerAnimated(true)

结果就可以了:

可以直接弹出之前的一系列的ViewController,直到root的viewcontroller

然后此处再接着选择对应的tab,

接着再去打开对应的,新创建的讨论组的vc,即可:

dispatch_async(dispatch_get_main_queue(), { () -> Void in
                        //pop out previous many vc, goto main vc
                        //[0] <JianDao.MainViewController: 0x7f80db037600>
                        self.navigationController?.popToRootViewControllerAnimated(true)
                        //select the conversation vc
                        gMainVC.selectedIndex = 0
                        //jump to newly created group/topic conversation
                        let groupTopicMsgTVC:MessageTableViewController = gConversationTVC.getMsgTVCFromContactId(newGroupTopicId)
//                        self.showViewController(groupTopicMsgTVC, sender: groupTopicMsgTVC)
                        gConversationTVC.showViewController(groupTopicMsgTVC, sender: groupTopicMsgTVC)
})

[总结]

此处,很明显,没有解决:

通过:

self.navigationController?.popViewControllerAnimated(true)

之后,再去显示新的vc:

gConversationTVC.showViewController(groupTopicMsgTVC, sender: groupTopicMsgTVC)

结果却导致,导航栏中内容错乱:

左边的按钮,中间的标题,右边的按钮,都重叠显示了。

而最终也没有找到根本原因。

但是通过:

self.navigationController?.popToRootViewControllerAnimated(true)

去跳转到navigationController的root的vc,从而避免,规避了,此导航栏显示错乱的问题。

转载请注明:在路上 » [已规避]swift关闭ViewController后显示新页面结果导航栏标题重叠错乱

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
91 queries in 0.243 seconds, using 22.16MB memory