I have 4 view controllers I am dealing with in this question. For simplictiy sake I will refer to them as vcA, vcB, vcC, and vcD.
我在这个问题上有4个视图控制器。为了简单起见,我将它们称为vcA,vcB,vcC和vcD。
Overall what I want to do is dismiss two view controllers and then push the third view controller to the 4th view controller. Essentially this is how the path would go: vcA(dismissed) -> vcB(dismissed) -> vcC pushes to vcD(final destination).
总的来说,我想要做的是关闭两个视图控制器,然后将第三个视图控制器推送到第四个视图控制器。基本上这就是路径的方式:vcA(被解雇) - > vcB(被解雇) - > vcC推送到vcD(最终目的地)。
Here is my current code for the process. Please note I am able to dismiss the first two view controllers but I can't figure out how to push the third view controller. Anyways here is my code:
这是我目前的流程代码。请注意我可以解除前两个视图控制器,但我无法弄清楚如何推送第三个视图控制器。无论如何这里是我的代码:
CODE FOR vcA:
vcA代码:
@IBAction func createGroupButtonTapped(_ sender: Any) {
if groupNameTextField.text == "" {
ProgressHUD.showError("Please enter a group title")
} else {
self.presentingViewController?.dismiss(animated: false, completion: nil)
NewConversationController().showDisplayConversationsController(title: self.groupNameTextField.text!, groupThumbnail: self.groupImageView, members: CreateConversationPopOver.groupMembers)
self.presentingViewController?.dismiss(animated: true, completion: nil)
}
}
In the code above I dismiss the first two view controllers and also call a function in vcB. This function in vcB calls a function in vcC. Here is the code for the functions:
在上面的代码中,我解除了前两个视图控制器,并在vcB中调用了一个函数。 vcB中的此函数调用vcC中的函数。这是函数的代码:
FUNCTION IN vcB:
vcB中的功能:
func showDisplayConversationsController(title: String, groupThumbnail: UIImageView, members: Array<String>) {
dismiss(animated: true, completion: nil)
DisplayConversationsController().showViewChatController(title: title, groupThumbnail: groupThumbnail, members: members)
}
FUNCTION IN vcC:
vcC中的功能:
func showViewChatController(title: String, groupThumbnail: UIImageView, members: Array<String>) {
let viewChatController = ViewChatController(collectionViewLayout: UICollectionViewFlowLayout())
viewChatController.hidesBottomBarWhenPushed = true
viewChatController.groupThumbnail = groupThumbnail
viewChatController.groupMembers = members
viewChatController.groupTitle = title
navigationController?.pushViewController(viewChatController, animated: true)
}
The problem occurs in VCC where the view controller never pushes to the final destination otherwise known as vcD. I have added breakpoints within the function above and they are all called. So the code is being run.
问题发生在VCC中,视图控制器从不推送到最终目的地,也称为vcD。我在上面的函数中添加了断点,它们都被调用了。所以代码正在运行。
I don't know why the view controller won't push because even after numerous testing, all my functions are being called.
我不知道为什么视图控制器不会推动,因为即使经过多次测试,我的所有函数都被调用。
Any help would be appreciated. Thanks!
任何帮助,将不胜感激。谢谢!
PS: In case you are wondering why I want to dismiss views and present them this way, it is because I need to pass data through these views into a chat log controller.
PS:如果你想知道为什么我要解雇视图并以这种方式呈现它们,那是因为我需要将数据通过这些视图传递到聊天记录控制器中。
2 个解决方案
#1
1
first.
check vcC's navigationController, it may be nil.
It seems you call Class methods NewConversationController
DisplayConversationsController
, (not familiar with swift, or these two are ) not instance methods. Maybe it not the right vcC, just a new vcC?
第一。检查vcC的navigationController,它可能是零。看来你调用类方法NewConversationController DisplayConversationsController,(不熟悉swift,或者这两个都是)不是实例方法。也许它不是正确的vcC,只是一个新的vcC?
PS: It is quite strange that you vcA.presentingViewController dismiss twice and according to what you say, It just dismiss fine. if you can describe how you present vcA, vcB or give a demo to show how it work, I think it may be helpful.
PS:很奇怪你vcA.presentingViewController被解雇两次并根据你的说法,它只是解雇罚款。如果你能描述你如何展示vcA,vcB或者给出一个演示来展示它是如何工作的,我想它可能会有所帮助。
#2
0
You can use Notification Pattern for the same. If you want to switch directly from vcA to VcD, fire notification in vcA before switching to vcD. Make vcB, vcC as listener to the same notification. When u directly switch from vcA to vcD, vcB and vcC will get notified if they already present. Handle the notification in vcB and vcC and hence dismissViewController
or PopViewController
as required. You can even pass data through from vcA directly to vcD using notification.
您可以使用通知模式。如果要直接从vcA切换到VcD,请在切换到vcD之前在vcA中触发通知。使vcB,vcC成为同一通知的监听器。当您直接从vcA切换到vcD时,如果vcB和vcC已经存在,则会收到通知。在vcB和vcC中处理通知,因此根据需要解除ViewController或PopViewController。您甚至可以使用通知将数据从vcA直接传递到vcD。
You can't push a view controller into a view dismissed, if it's dismissed it disappears so it's not logical to push another view, cause the parent view controller is deleted.
您无法将视图控制器推送到视图中,如果它被解除则会消失,因此推送另一个视图是不合逻辑的,导致父视图控制器被删除。
What you have to do is - vcA --> Present vcB --> Dismiss vcB --> Present vcC Push vcD on vcC > Dismiss vcC
你要做的是 - vcA - >现在的vcB - >解散vcB - >在vcC上出现vcC推送vcD>解除vcC
You can do it with notifications. You can even accomplish the task using delegation pattern. Make vcB as delegate of vcC that notifies vcB when vcB dismisses then dismiss vcB and then just push vcD on vcC.
您可以通过通知执行此操作。您甚至可以使用委托模式完成任务。将vcB作为vcC的委托,当vcB解散时通知vcB然后解除vcB然后只是在vcC上推送vcD。
Hope it helps. Happy Coding!!
希望能帮助到你。快乐编码!!
#1
1
first.
check vcC's navigationController, it may be nil.
It seems you call Class methods NewConversationController
DisplayConversationsController
, (not familiar with swift, or these two are ) not instance methods. Maybe it not the right vcC, just a new vcC?
第一。检查vcC的navigationController,它可能是零。看来你调用类方法NewConversationController DisplayConversationsController,(不熟悉swift,或者这两个都是)不是实例方法。也许它不是正确的vcC,只是一个新的vcC?
PS: It is quite strange that you vcA.presentingViewController dismiss twice and according to what you say, It just dismiss fine. if you can describe how you present vcA, vcB or give a demo to show how it work, I think it may be helpful.
PS:很奇怪你vcA.presentingViewController被解雇两次并根据你的说法,它只是解雇罚款。如果你能描述你如何展示vcA,vcB或者给出一个演示来展示它是如何工作的,我想它可能会有所帮助。
#2
0
You can use Notification Pattern for the same. If you want to switch directly from vcA to VcD, fire notification in vcA before switching to vcD. Make vcB, vcC as listener to the same notification. When u directly switch from vcA to vcD, vcB and vcC will get notified if they already present. Handle the notification in vcB and vcC and hence dismissViewController
or PopViewController
as required. You can even pass data through from vcA directly to vcD using notification.
您可以使用通知模式。如果要直接从vcA切换到VcD,请在切换到vcD之前在vcA中触发通知。使vcB,vcC成为同一通知的监听器。当您直接从vcA切换到vcD时,如果vcB和vcC已经存在,则会收到通知。在vcB和vcC中处理通知,因此根据需要解除ViewController或PopViewController。您甚至可以使用通知将数据从vcA直接传递到vcD。
You can't push a view controller into a view dismissed, if it's dismissed it disappears so it's not logical to push another view, cause the parent view controller is deleted.
您无法将视图控制器推送到视图中,如果它被解除则会消失,因此推送另一个视图是不合逻辑的,导致父视图控制器被删除。
What you have to do is - vcA --> Present vcB --> Dismiss vcB --> Present vcC Push vcD on vcC > Dismiss vcC
你要做的是 - vcA - >现在的vcB - >解散vcB - >在vcC上出现vcC推送vcD>解除vcC
You can do it with notifications. You can even accomplish the task using delegation pattern. Make vcB as delegate of vcC that notifies vcB when vcB dismisses then dismiss vcB and then just push vcD on vcC.
您可以通过通知执行此操作。您甚至可以使用委托模式完成任务。将vcB作为vcC的委托,当vcB解散时通知vcB然后解除vcB然后只是在vcC上推送vcD。
Hope it helps. Happy Coding!!
希望能帮助到你。快乐编码!!