我有一个主窗口,我只是加载像这样的集合视图
let urlString = "http://example.url"
let url = NSURL(string: urlString)!
let urlSession = URLSession.shared
let jsonQuery = urlSession.dataTask(with: url as URL, completionHandler: {
data, response, error -> Void in
if (error != nil) {
print("ERROR \(error!.localizedDescription)")
}else{
let jsonResult = (try! JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.mutableContainers)) as! NSDictionary
let arrayImagenes1 = jsonResult["franjas"]! as! NSMutableArray
arrayImagenes1.removeObject(at: 0)
arrayImagenes1.removeObject(at: 0)
self.arrayImagenes = arrayImagenes1 as NSArray
print (self.arrayImagenes)
self.franjasCollection.reloadData()
}
})
jsonQuery.resume()
在那个视图中,我调用了一个登录窗口,我只需登录这个应用程序
let urlString = "http://example.login"
let url = NSURL(string: urlString)!
let urlSession = URLSession.shared
let jsonQuery = urlSession.dataTask(with: url as URL, completionHandler: {
data, response, error -> Void in
if (error != nil) {
print("ERROR \(error!.localizedDescription)")
}else{
let jsonResult = (try! JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.mutableContainers)) as! NSDictionary
if jsonResult["username"] != nil {
let usuario = jsonResult["username"]! as? NSString
DispatchQueue.main.async {
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
let username = Usuario(context: context) // Link Task & Context
username.username = usuario! as String
}
(UIApplication.shared.delegate as! AppDelegate).saveContext()
Variables.loginbool = true
let _ = self.navigationController?.popViewController(animated: true)
} else {
let alert = UIAlertController(title: "Inti", message: (jsonResult["error"]! as! NSString) as String, preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
}
})
jsonQuery.resume()
因此,在用户成功登录应用程序后,我使用此行
let _ = self.navigationController?.popViewController(animated: true)
但是当它回到主视图时,集合视图被冻结,我无法在其中导航,我只能单击登录按钮
PD:这是一个苹果电视应用