gpt4 book ai didi

两个 View 之间的快速转换需要很长时间

转载 作者:行者123 更新时间:2023-11-28 13:11:22 24 4
gpt4 key购买 nike

使用 window.rootViewController 两个 View 之间的转换大约需要 1 分钟

当返回成功时,我可以连接到我的服务器,我更改了我的 rootViewControler,但这需要很长时间。如果我跳转连接代码, View 会立即出现吗?

    self.logingSpinner.startAnimating();

var request = NSMutableURLRequest(URL: NSURL(string: "http://apps/appsAuth")!)
var session = NSURLSession.sharedSession()
request.HTTPMethod = "POST"
var err: NSError?

var bodyData="siren=\(entrepriseId.text)&email=\(email.text)&pwd=\(pwd.text)";

request.HTTPBody = bodyData.dataUsingEncoding(NSUTF8StringEncoding);

request.HTTPMethod = "POST"
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")

var task = session.dataTaskWithRequest(request, completionHandler: {data, response, error -> Void in

var strData = NSString(data: data, encoding: NSUTF8StringEncoding)

var err: NSError?
var json = NSJSONSerialization.JSONObjectWithData(data, options: .MutableLeaves, error: &err) as? NSDictionary


if(err != nil) {
println(err!.localizedDescription)
let jsonStr = NSString(data: data, encoding: NSUTF8StringEncoding)
println("Error could not parse JSON: '\(jsonStr)'")
}
else {

if let parseJSON = json {
println("data retour \(parseJSON)")

var success = parseJSON["error"] as? Int
println("Succes: \(success)")


dispatch_async(dispatch_get_main_queue()) {
self.logingSpinner.stopAnimating();
bt.enabled = true;
bt.alpha = 1;
}

// si une erreur symfony est retournée
if(success==nil){ success = 3};

switch success!{
case 0:
println("auth success");
var data = userDefault.dictionaryForKey("userInfos")!
data["login"] = self.email.text;
data["siren"] = self.entrepriseId.text;
data["pwd"] = self.pwd.text;
data["isLogged"] = true;
data["hasCredential"] = true;

userDefault.setObject(data, forKey : "userInfos");
userDefault.synchronize();
//CHANGE root View Controller
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let initViewController: UIViewController = storyBoard.instantiateViewControllerWithIdentifier("viewAcc") as accueilViewController
var window :UIWindow = UIApplication.sharedApplication().keyWindow!
window.rootViewController = initViewController
window.makeKeyAndVisible()


case 1 :
println("auth failed")
default :
println("default");
}


}
else {
// Woa, okay the json object was nil, something went worng. Maybe the server isn't running?
let jsonStr = NSString(data: data, encoding: NSUTF8StringEncoding)
println("Error could not parse JSON: \(jsonStr)")
}



}
})

task.resume()

我已经尝试过使用 presentViewControler 转换是即时的,但是我在 View 中的图像消失了,只有按钮在位?
预先感谢您的帮助

最佳答案

负责减缓 View 转换的 NSURLSession

我还没有找到原因!但这是有罪的。这很奇怪,因为完成函数在最后。有人知道在完成函数之后是否有一个进程在运行。
抱歉我的英语很糟糕:-(

 let initViewController: UIViewController = storyBoard.instantiateViewControllerWithIdentifier("viewAcc") as accueilViewController
var window :UIWindow = UIApplication.sharedApplication().keyWindow!
window.rootViewController = initViewController
window.makeKeyAndVisible()
println("end")

在控制台中执行 println("end"),我在控制台中看到来 self 的 accueilviewcontroller viewDidAppear 函数的 println(viewdidload),但 View 在一分钟多后出现。

关于两个 View 之间的快速转换需要很长时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31181616/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com