简体   繁体   English

关闭MPC ViewController后,Segue没有运行

[英]Segue not running after MPC viewcontroller is dismissed

I have an action tied to pop up the MPC view controller however once this action is complected and the browser is dismissed I simply am lead back to my old view controller 我有一个动作可以弹出MPC视图控制器,但是一旦执行了该操作并且浏览器被关闭,我将直接回到我的旧视图控制器

func browserViewControllerDidFinish(
browserViewController: MCBrowserViewController!)  {
    // Called when the browser view controller is dismissed (ie the Done
    // button was tapped)
    func seguetoJoin(segue: UIStoryboardSegue, sender: AnyObject?) {
        var joinView: playMusicViewController = segue.destinationViewController as! playMusicViewController
         weak var delegate: MCBrowserViewControllerDelegate!

    }

    self.dismissViewControllerAnimated(true, completion: nil)

} }

You seem to be calling dismissViewController on the VC that is receiving the didFinish callback. 您似乎在正在接收didFinish回调的VC上调用dismissViewController。

You should move the segue code to the ViewController that needs to perform the segue, rather than performing it on a ViewController that is being dismissed. 您应该将安全代码移至需要执行安全代码的ViewController上,而不是在正在被关闭的ViewController上执行。

Also, these are unused 而且这些都没用

var joinView: playMusicViewController = segue.destinationViewController as! playMusicViewController
weak var delegate: MCBrowserViewControllerDelegate!

Update - 更新-

Following the comments below. 在下面的评论。

in mpcSubClass.m var viewControllerToPeformSegue: UIViewController! 在mpcSubClass.m中var viewControllerToPeformSegue:UIViewController!

func browserViewControllerDidFinish(browserViewController: MCBrowserViewController!)  {
    // animation:false as your segue will have an animation
    self.dismissViewControllerAnimated(false, completion: nil)
    self.viewControllerToPerformSegue.handleBrowserDidFinish()
}

in viewControllerToPerformSegue.m 在viewControllerToPerformSegue.m中

// when you initialise the MPC VC subclass
mpcVCSubclass.viewControllerToPerformSegue = self

func handleBrowserDidFinish()
{
     self.performSegueWithIdentifier("mainViewSegue", sender: self)
}

override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) 
{
     if segue.identifier == "mainViewSegue"
    {
        let mainVC = segue.destination as! MainVC
        // now pass any data to your main VC that it can load in viewWillAppear
    }
}

in storyboard 在故事板中

link viewControllerToPerformSegue to the MainVC and name the segue mainViewSegue 将viewControllerToPerformSegue链接到MainVC并将名称命名为mainViewSegue

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM