小编Nil*_*ell的帖子

警告:尝试在视图不在窗口层次结构中显示*on* - swift

我试图提出一个数据模型中ViewController 是否有任何已保存的数据.但是我收到以下错误:

警告:尝试显示其视图不在窗口层次结构中的*on*

相关代码:

override func viewDidLoad() {
    super.viewDidLoad()
    loginButton.backgroundColor = UIColor.orangeColor()

    var request = NSFetchRequest(entityName: "UserData")
    request.returnsObjectsAsFaults = false

    var appDel:AppDelegate = (UIApplication.sharedApplication().delegate as AppDelegate)
    var context:NSManagedObjectContext = appDel.managedObjectContext!

    var results:NSArray = context.executeFetchRequest(request, error: nil)!

    if(results.count <= 0){
        print("Inga resultat")
    } else {
        print("SWITCH VIEW PLOX")
        let internVC = self.storyboard?.instantiateViewControllerWithIdentifier("internVC") as internViewController
        self.presentViewController(internVC, animated: true, completion: nil)
    }
}
Run Code Online (Sandbox Code Playgroud)

我尝试过使用谷歌找到的不同解决方案但没有成功.

hierarchy ios presentviewcontroller swift

77
推荐指数
8
解决办法
9万
查看次数

Swift iOS API控制器停止工作

我正在使用一个文件来处理我对API的调用,如下所示:

import UIKit

protocol APIControllerProtocol {
    func JSONAPIResults(results: NSArray)

}

class APIController: NSObject {
    var delegate:APIControllerProtocol?

    func GetAPIResultsAsync(urlString:String, elementName:String) {

        //The Url that will be called
        var url = NSURL.URLWithString(urlString)
        //Create a request
        var request: NSURLRequest = NSURLRequest(URL: url)
        //Create a queue to hold the call
        var queue: NSOperationQueue = NSOperationQueue()

        // Sending Asynchronous request using NSURLConnection
        NSURLConnection.sendAsynchronousRequest(request, queue: queue, completionHandler:{(response:NSURLResponse!, responseData:NSData!, error: NSError!) ->Void in
            var error: AutoreleasingUnsafeMutablePointer<NSError?> = nil
            //Serialize the JSON result into a dictionary
            let jsonResult: …
Run Code Online (Sandbox Code Playgroud)

json ios nsjsonserialization swift

2
推荐指数
1
解决办法
3222
查看次数