Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios performseguewithidentifier在一个viewDidLoad中工作,但在另一个viewDidLoad中不工作,使用;“显示”;赛格_Ios_Objective C_Iphone_Navigation_Viewdidload - Fatal编程技术网

Ios performseguewithidentifier在一个viewDidLoad中工作,但在另一个viewDidLoad中不工作,使用;“显示”;赛格

Ios performseguewithidentifier在一个viewDidLoad中工作,但在另一个viewDidLoad中不工作,使用;“显示”;赛格,ios,objective-c,iphone,navigation,viewdidload,Ios,Objective C,Iphone,Navigation,Viewdidload,以下是第一个viewDidLoad: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. if ([[NSUserDefaults standardUserDefaults] objectForKey:@"Tutorial"]) { [self performSegueWithIdentifier:@"fromTutori

以下是第一个viewDidLoad:

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    if ([[NSUserDefaults standardUserDefaults] objectForKey:@"Tutorial"]) {
        [self performSegueWithIdentifier:@"fromTutorialToWelcome" sender:self];
    }else{
        [self setupVc];
    }
}
下面是第二个,在下面的视图控制器中:

- (void)viewDidLoad {
    [super viewDidLoad];
    if ([[NSUserDefaults standardUserDefaults] objectForKey:@"loginTesting"]) { //This evaluates to true, I double and triple checked.

        [self performSegueWithIdentifier:@"fromWelcomeToEntryPoint" sender:self];
    }else{
        [self setupVc];
    }
}
这两个序列都是Show序列,那么为什么第二个序列不起作用呢

编辑:强调segue的类型,因为它不再是iOS5


EDIT2:我想我没有正确地解释我想做什么。我希望在不显示第二个视图控制器的情况下显示第三个视图控制器。

当您从非运行状态打开应用程序时,每个视图只加载到内存中一次。在第二个视图控制器中,将其从viewDidLoad移动到ViewDidDisplay。我相信它会解决你的问题。如果没有,请告诉我,我将尝试调试它

编辑:

这是我做的一个工作示例

第一次: 第一视图控制器->第二视图控制器->第三视图控制器

第二次: FirstViewController->ThirdViewController(没有看到SecondViewController!)

FirstViewController.swift:

import UIKit

class FirstViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func ToSecondPressed(sender: AnyObject) {

        if let skip = NSUserDefaults.standardUserDefaults().valueForKey("SkipSecond") as? Bool{

            let Third: ThirdViewController = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle()).instantiateViewControllerWithIdentifier("Third") as! ThirdViewController

            UIApplication.sharedApplication().delegate?.window??.rootViewController = Third
        }

        else{

            let Second: SecondViewController = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle()).instantiateViewControllerWithIdentifier("Second") as! SecondViewController

            NSUserDefaults.standardUserDefaults().setBool(true, forKey: "SkipSecond")
            UIApplication.sharedApplication().delegate?.window??.rootViewController = Second
        }

    }

}
import UIKit

class SecondViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func ToThirdPressed(sender: AnyObject) {
        let Third = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle()).instantiateViewControllerWithIdentifier("Third") as? ThirdViewController

        UIApplication.sharedApplication().delegate?.window??.rootViewController = Third
    }


}
import UIKit

class ThirdViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}
SecondViewController.swift:

import UIKit

class FirstViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func ToSecondPressed(sender: AnyObject) {

        if let skip = NSUserDefaults.standardUserDefaults().valueForKey("SkipSecond") as? Bool{

            let Third: ThirdViewController = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle()).instantiateViewControllerWithIdentifier("Third") as! ThirdViewController

            UIApplication.sharedApplication().delegate?.window??.rootViewController = Third
        }

        else{

            let Second: SecondViewController = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle()).instantiateViewControllerWithIdentifier("Second") as! SecondViewController

            NSUserDefaults.standardUserDefaults().setBool(true, forKey: "SkipSecond")
            UIApplication.sharedApplication().delegate?.window??.rootViewController = Second
        }

    }

}
import UIKit

class SecondViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func ToThirdPressed(sender: AnyObject) {
        let Third = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle()).instantiateViewControllerWithIdentifier("Third") as? ThirdViewController

        UIApplication.sharedApplication().delegate?.window??.rootViewController = Third
    }


}
import UIKit

class ThirdViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}
ThirdViewController.swift:

import UIKit

class FirstViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func ToSecondPressed(sender: AnyObject) {

        if let skip = NSUserDefaults.standardUserDefaults().valueForKey("SkipSecond") as? Bool{

            let Third: ThirdViewController = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle()).instantiateViewControllerWithIdentifier("Third") as! ThirdViewController

            UIApplication.sharedApplication().delegate?.window??.rootViewController = Third
        }

        else{

            let Second: SecondViewController = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle()).instantiateViewControllerWithIdentifier("Second") as! SecondViewController

            NSUserDefaults.standardUserDefaults().setBool(true, forKey: "SkipSecond")
            UIApplication.sharedApplication().delegate?.window??.rootViewController = Second
        }

    }

}
import UIKit

class SecondViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func ToThirdPressed(sender: AnyObject) {
        let Third = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle()).instantiateViewControllerWithIdentifier("Third") as? ThirdViewController

        UIApplication.sharedApplication().delegate?.window??.rootViewController = Third
    }


}
import UIKit

class ThirdViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

会发生什么?你收到了什么信息?您是否在
prepareforsgue
中设置了断点或添加了日志记录?没有发生任何情况,应用程序不会移动到任何位置。我刚刚重写了PrepareForSegue,但它只有一个NSLogI。我不认为在viewDidLoad中执行分段是个好主意。现在还为时过早->虽然viewDidLoad只触发过一次,但这不应该成为问题,因为第二个ViewController在第一个segue启动之前不会实例化。而且,虽然ViewDidDisplay确实解决了导航问题,但我最终看到了第二个viewcontroller,我想避免它,并跳到我正在尝试的第三个viewcontrollerreach@Jargen89我在我的答案中添加了工作示例。这里的主键是操纵应用程序的窗口,并根据所需的viewController(第二个或第三个)进行分配。我不喜欢segues,更喜欢使用故事板的InstanceEviewController方法。。。