我的ViewControllers没有正确解雇

时间:2015-05-31 21:03:29

标签: ios swift delegates viewcontroller

我有三个viewControllers,想法是,从ViewController到ViewOneController,再到ViewTwoControler,然后我想直接去ViewController,但是当我这样做时,我的内存有点上升,这就是viewControllerDelegate < / p>

protocol ViewControllerDelegate{

func ViewControllerDidFinish(controller: ViewController)

}

这是viewTwo,我试图去ViewController

protocol ViewTwoDelegate{

func ViewTwoDidFinish(controller: ViewTwo)

}

class ViewTwo: UIViewController, ViewControllerDelegate {
    var button: UIButton!
    var delegate: ViewTwoDelegate? = nil
    override func viewDidLoad() {
        super.viewDidLoad()

    button = UIButton.buttonWithType(UIButtonType.System) as! UIButton
    button.frame = CGRectMake(self.view.frame.size.width/2 - button.frame.size.width, 100, 250, 50)
    button.layer.cornerRadius = 3
    button.backgroundColor = UIColor.blueColor()
    button.center.x = self.view.center.x
    button.setTitle("ViewController", forState: UIControlState.Normal)
    button.addTarget(self, action: "ViewControllerAction:", forControlEvents: UIControlEvents.TouchUpInside)
    button.tintColor = UIColor.whiteColor()
    view.addSubview(button)
}

func ViewControllerAction(sender: UIButton!){
    var materialsViewController: ViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("view") as! ViewController
    self.presentViewController(materialsViewController, animated: true, completion: nil)

}

func ViewControllerDidFinish(controller: ViewController){
    self.dismissViewControllerAnimated(true, completion: nil)
}

其他两个控制器大多相同

编辑:我试过这个

self.dismissViewControllerAnimated(true, completion: { () -> Void in
        self.presentingViewController?.dismissViewControllerAnimated(true, completion: nil)
    })

当我尝试这个时,它只解散自己,但没有呈现。

self.dismissViewControllerAnimated(true, completion: nil)
self.presentingViewController?.dismissViewControllerAnimated(true, completion: nil)

它可以工作,但对于两个viewControllers,如果我需要更多?

我真的需要一些帮助,请

0 个答案:

没有答案