Setting title of UINavigationbar not working

前端 未结 2 1164
孤独总比滥情好
孤独总比滥情好 2021-01-26 01:43

I\'ve looked through a few online tutorials, but nothing is working.

That\'s the code of my viewController:

import UIKit

class ViewController: UINavigat         


        
相关标签:
2条回答
  • 2021-01-26 02:21

    First of all in your storyboard select your view controller and then

    Editor -> Embed In -> Navigation Controller

    then in your ViewController class add

    self.title = "AAA"
    

    in your viewDidLoad method and your code will look like:

    class ViewController: UIViewController {
    
        override func viewDidLoad() {
            super.viewDidLoad()
            self.title = "AAA"
        }
    }
    

    You need to replace UINavigationController with UIViewController

    0 讨论(0)
  • 2021-01-26 02:36

    Select ViewController from the storyboard.

    Go to the Editor and Embed with Navigation Controller

    1) Select Navigation Item and set title from the storyboard.

    2) By Programmatically

    class ViewController: UIViewController {
    
        override func viewDidLoad() {
            super.viewDidLoad()
            self.title = "Your Title"
        }
    }
    
    0 讨论(0)
提交回复
热议问题