【发布时间】:2016-07-11 12:29:24
【问题描述】:
我正在尝试从登录传递到视图菜单控制器(ID 故事板:菜单)。
要切换视图控制器,我有一个登录按钮,登录与 Login.swift 相关联。
在 Login.swift 中,通过单击 LOGIN 按钮执行以下操作:
Request().login(tag, email: email, pass: pass)
在请求中我有这个:
class Request {
func login(tag : String, email : String, pass : String){
let url = NSURL(string: "xxx");
let request = NSMutableURLRequest(URL:url!)
request.HTTPMethod = "POST";
let postString = "tag="+tag+"&email="+email+"&password="+pass;
request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding);
let session = NSURLSession.sharedSession();
let task = session.dataTaskWithRequest(request, completionHandler: {data, response, error -> Void in
let json = JSON(data: data!)
Login().passPostData(json)
});
task.resume();
}}
在登录 passPostData 中:
func passPostData(json: JSON){
let total = json.count
for i in 0..<total{
let id = json[i]["id"].string!
let username = json[i]["username"].string!
let birthday = json[i]["birthday"].string!
let location = json[i]["location"].string!
let email = json[i]["email"].string!
let photo = json[i]["photo"].string!
print(id + " - " + username + " - " + birthday + " - " + location + " - " + email + " - " + photo)
}
SwiftLoading().hideLoading()
//self.performSegueWithIdentifier("goToMenu", sender: self)
//let menuController = self.storyboard?.instantiateViewControllerWithIdentifier("menu") as? ViewMenuController
//self.navigationController?.pushViewController(menuController!, animated: true)
//let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil);
//let vc : UIViewController = storyboard.instantiateViewControllerWithIdentifier("menu") as UIViewController;
//self.presentViewController(vc, animated: true, completion: nil);
}
注释行是我尝试进入 View Menu Controller 的所有方式。
尝试时:
self.performSegueWithIdentifier("goToMenu", sender: self)
我收到此错误:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<xxx.Login: 0x7f9d28545000>) has no segue with identifier 'goToMenu''
但是登录和视图菜单控制器之间的segue被分配了标识符goToMenu
尝试时:
let menuController = self.storyboard?.instantiateViewControllerWithIdentifier("menu") as? ViewMenuController
self.navigationController?.pushViewController(menuController!, animated: true)
不工作或失败。
尝试时:
let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil);
let vc : UIViewController = storyboard.instantiateViewControllerWithIdentifier("menu") as UIViewController;
self.presentViewController(vc, animated: true, completion: nil);
我收到此错误:
Warning: Attempt to present <xxx.ViewMenuController: 0x7f9139ef46e0> on <xxx.Login: 0x7f9139d871c0> whose view is not in the window hierarchy!
我该怎么做?
【问题讨论】:
-
两件事你忘记了
-
您需要将
ViewController嵌入UINavugationController。
标签: ios iphone swift xcode segue