cph*_*ill 1 ios parse-platform swift
我正在尝试创建一个函数,在应用程序启动时,应用程序检查是否有当前登录的Parse用户,如果这是真的,那么用户应该绕过登录屏幕并进入我的视图位于选项卡中查看控制器.如果当前没有用户登录,则打开登录视图,默认情况下会在应用程序加载时打开.我通过在我的登录视图的viewWillAppear函数中创建一个if语句来破解这个功能,如果这是真的,那么instantiateViewControllerWithIdentifier(),但由于我的名字没有标识符,我的应用程序立即崩溃.
reason: 'Storyboard (<UIStoryboard: 0x7ffbf3e82190>) doesn't contain a view controller with identifier 'ProfileSettingsViewController'
Run Code Online (Sandbox Code Playgroud)
现在我可能会遗漏一些东西,但是我在哪里设置视图控制器的标识符?或者我的班级名称是我目前假设的标识符?
在一个相关的问题中,这是实现我的目标的最佳方式吗?
这是我的登录控制器逻辑:
override func viewWillAppear(animated: Bool) {
var currentUser = PFUser.currentUser()
if currentUser != nil {
self.storyboard?.instantiateViewControllerWithIdentifier("ProfileSettingsViewController")
}
}
Run Code Online (Sandbox Code Playgroud)
以下是用户已登录时应打开的视图ProfileSettingsViewController.swift:
import UIKit
class ProfileSettingsViewController: UIViewController {
override func viewWillAppear(animated: Bool) {
self.tabBarController?.navigationItem.setHidesBackButton(true, animated:true);
//self.tabBarController?.navigationItem.title = "Profile Settings"
self.navigationController?.navigationItem.title = "ffff"
}
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func logoutButton(sender: AnyObject) {
PFUser.logOut()
var currentUser = PFUser.currentUser()
self.performSegueWithIdentifier("userLoggedOut", sender: self)
self.navigationController?.setNavigationBarHidden(self.navigationController?.navigationBarHidden == false, animated: true)
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
Run Code Online (Sandbox Code Playgroud)
我以前没有使用Parse,但是为了授权,我通常让AppDelegate来处理初始视图控制器.
// member variables
var storyboard : UIStoryboard?;
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
self.storyboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle());
var currentUser = PFUser.currentUser()
if currentUser != nil {
self.window?.rootViewController = self.storyboard?.instantiateViewControllerWithIdentifier("ProfileSettingsViewController");
}
return true;
}
Run Code Online (Sandbox Code Playgroud)
我很确定这将在视图控制器内部工作,因为在您的代码中,您没有将实例化的控制器分配给根视图控制器.但是,我认为AppDelegate应该注意更改Root View Controller,而不是UIViewControllers.
编辑:对不起,忘了提及你的错误.转到故事板并单击ProfileSettingsViewController并转到侧栏中的第3个选项卡,其中有一个Storyboard ID.将名称设置为"ProfileSettingsViewController"(或任何你想要的),它将找到控制器.UIStoryboard.instantiateViewControllerWithIdentifier在故事板中搜索具有给定Storyboard ID的控制器.
| 归档时间: |
|
| 查看次数: |
4460 次 |
| 最近记录: |