Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.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 在swift中更改屏幕_Ios_Iphone_Swift_Storyboard_Xcode 6.2 - Fatal编程技术网

Ios 在swift中更改屏幕

Ios 在swift中更改屏幕,ios,iphone,swift,storyboard,xcode-6.2,Ios,Iphone,Swift,Storyboard,Xcode 6.2,以下是我的应用程序的情节提要: 应用程序在屏幕1上与服务器建立连接,与服务器的所有通信仅在此屏幕的代码中执行。我们在screen4上发出请求,并通过screen1的代码将其发送到服务器,应用程序接收服务器的响应。若应用程序得到成功响应,那个么应用程序应该显示屏幕5,在那个里我得到了错误。 我写了不同的代码行,但失败了。以下是我现在使用的代码行: import UIKit class logoViewController: UIViewController { @IBOutlet w

以下是我的应用程序的情节提要:

应用程序在屏幕1上与服务器建立连接,与服务器的所有通信仅在此屏幕的代码中执行。我们在screen4上发出请求,并通过screen1的代码将其发送到服务器,应用程序接收服务器的响应。若应用程序得到成功响应,那个么应用程序应该显示屏幕5,在那个里我得到了错误。 我写了不同的代码行,但失败了。以下是我现在使用的代码行:

import UIKit

class logoViewController: UIViewController {

    @IBOutlet weak var act: UIActivityIndicatorView!
    override func viewDidLoad() {
        super.viewDidLoad()

        self.act.startAnimating()



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


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

    // syncreq function is called from the connectionViewController.
    // connectionViewController is the common class for connecting to the remote server  
    func syncreq (JSONdata: AnyObject) { // Proceesing for PRMS response


       // Getting the value from the JSON
        var Successful = self.getIntFromJSON(JSONdata as NSDictionary, key: "Successful")


        println("Value of Successful : \(Successful)")

        if (Successful == 0){

            //Method1 not worked
  // let adduser = regVC()
  // self.presentViewController(adducer, animated: true, completion: nil)
   //Method2 not worked
 //let adducer =    self.storyboard?.instantiateViewControllerWithIdentifier("registrationID") as regVC

        //self.navigationController?.pushViewController(adducer, animated: true)

           //Method3 not worked
            //let secondViewController = self.storyboard?.instantiateViewControllerWithIdentifier("registrationID") as regVC

            //self.navigationController?.pushViewController(secondViewController, animated: true)
            //performSegueWithIdentifier("registrationID", sender: self)


            let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
            var setViewController = mainStoryboard.instantiateViewControllerWithIdentifier("registrationID") as RegisterViewController
            self.presentViewController(setViewController, animated: false, completion: nil)

        }
        else if (Successful == 1){
             let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
            var setViewController = mainStoryboard.instantiateViewControllerWithIdentifier("mnuID") as menuViewController
            self.presentViewController(setViewController, animated: false, completion: nil)
        }



    }

    func getIntFromJSON(data: NSDictionary, key: String) -> Int {

        let info : AnyObject? = data[key]
        // println("Value of data[key] : \(key)")

        if let info = data[key] as? Int {
            println("Value of value for \(key) : \(info)")
            return info
        }

        else {
            return 0

        }

    }

}
我得到了以下错误:

Warning: Attempt to present <project.screen5: 0x7a094790> on <project.ViewController: 0x79639d90> whose view is not in the window hierarchy!
警告:尝试显示其视图不在窗口层次结构中的对象!
错误截图:
您的问题是ViewController 1的视图不在窗口层次结构中,因此ViewController 1无法显示模式VC

最干净的解决方案是改变你的应用程序架构设计——让一个视图控制器执行所有网络请求可能会比这一个更复杂

然而,对于“仅使其工作”解决方案,您可以从导航控制器提供模态VC,即

self.navigationController?.presentViewController(setViewController, animated: false, completion: nil)

您是否已将类正确初始化为视图控制器?您能否告诉我如何在窗口层次结构中添加ViewController 1。我也尝试了您的解决方案,但它在self.navigationController?.presentViewController(setViewController,动画:false,完成:nil)代码上出现ad异常错误。@AmitRaj它引发了什么异常?视图位于窗口层次结构中意味着它是可见
UIWindow
的子视图,在大多数情况下,它意味着视图是可见的。你不能只是将ViewController 1的视图添加到层次结构中-如果你想让它可见,你需要在导航控制器中弹出它之后的所有VCs。你是说我需要为每个视图控制器添加导航控件吗?不,我只是想解释寡妇层次结构的含义。并要求您发布在回答中使用解决方案时遇到的异常我在问题中添加了异常的屏幕截图