ios – Swift – 导航视图控制器不出现标题

我有一个导航视图控制器,在操作时将一个segue发送到标签栏视图控制器.由于这个segue,选项卡式视图控制器继承导航栏.我正在尝试将标题应用于附加到标签栏视图控制器的我的一个视图控制器,但是通过代码设置标题对我来说不起作用.有谁知道原因可能是什么?

这是我的故事板的图片

带有注销按钮的视图控制器是我试图在导航栏(代码)中设置标题的地方:

import UIKit

class ProfileSettingsViewController: UIViewController {

    override func viewWillAppear(animated: Bool) {

        self.navigationItem.title = "Profile Settings"

    }

    override func viewDidLoad() {
        super.viewDidLoad()

        self.navigationItem.leftBarButtonItem = nil


    }



    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)

    }

}

导航控制器中嵌入的视图控制器触发到标签栏控制器的segue:

import UIKit

class UserRegistrationViewController: UIViewController {


    func displayAlert(title:String,error:String) {

        var alert = UIAlertController(title: title,message: error,preferredStyle: UIAlertControllerStyle.Alert)

        alert.addAction(UIAlertAction(title: "OK",style: .Default,handler: {
            action in



        }))

        self.presentViewController(alert,animated: true,completion: nil)


    }

    @IBOutlet var usernameTextField: UITextField!

    @IBOutlet var emailTextField: UITextField!

    @IBOutlet var passwordTextField: UITextField!


    override func viewDidLoad() {
        super.viewDidLoad()


    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // dispose of any resources that can be recreated.
    }


    @IBAction func registerUser(sender: AnyObject) {

        var error = ""

        if usernameTextField.text == nil || emailTextField.text == nil || passwordTextField.text == nil {

            error = "Please enter a username,email and password"

        }


        if error != "" {

            displayAlert("Error In Form",error: error)

        } else {

            var user = PFUser.currentUser()

            user.username = usernameTextField.text
            user.password = passwordTextField.text
            user.email = emailTextField.text

            user.saveInBackgroundWithBlock {
                (succeeded: Bool!,signupError: NSError!) -> Void in
                if signupError == nil {

                    println(user.username)
                    println(user.password)
                    println(user.email)


                    self.performSegueWithIdentifier("successfulRegistration",sender: self)

                    self.navigationController?.setNavigationBarHidden(self.navigationController?.navigationBarHidden == false,animated: true)

                    // Hooray! Let them use the app Now.
                } else {

                    if let errorString = signupError.userInfo?["error"] as? Nsstring {
                        error = errorString
                    } else {

                        error = "Please try again later."

                    }


                    self.displayAlert("Could Not Sign Up",error: error)

                }
            }


        }


    }



}

解决方法

这对我有用:self.parent?.title =“nav bar title”

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...