【发布时间】:2016-07-18 14:59:05
【问题描述】:
在我的 swift 应用程序中,我有一个带有按钮的 UIViewController。这个按钮打开了 2 号 UIViewController 并且用户有另一个按钮。当用户按下它时 - 他会打开 3 号 UIViewController。还有一个按钮,当用户按下它时 - 他会调用代码:
self.dismissViewControllerAnimated(false, completion: nil)
多亏了它,3 号 UIViewController 消失了,用户看到了 2 号 UIViewController。我的问题是 - 有没有办法也解除 2 号 UIViewController 以便用户可以从 3 号顺利返回到 1 号?
现在我创建了一个函数并通过协议调用它:
UIViewController 2 号:
protocol HandleYourFullRequest: class {
func hideContainer()
}
class FullRequest: UIViewController, HandleYourFullRequest{
func hideContainer(){
self.dismissViewControllerAnimated(false, completion: nil)
}
@IBAction func exitbuttonaction(sender: AnyObject) {
self.performSegueWithIdentifier("temporarySegue", sender: self)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "temporarySegue"){
if let fullRequestDetails = segue.destinationViewController as? YourFullRequest
{
fullRequestDetails.delegateRequest = self
}
}
}
}
UIViewController 3 号:
class YourFullRequest: UIViewController{
var delegateRequest:HandleYourFullRequest?
@IBAction func exitbuttonaction(sender: AnyObject) {
self.dismissViewControllerAnimated(true, completion: nil)
delegateRequest?.hideContainer()
}
}
但是当用户按下按钮时,使用该解决方案 - UIViewController 3 号消失,UIViewController 2 号出现一秒钟然后消失。有没有办法在不向用户显示的情况下删除数字 2 并直接将他指向数字 1?
【问题讨论】:
标签: ios swift uiviewcontroller segue uistoryboardsegue