Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I was trying to add a Barbutton to my navitem but it does not get added I am using live playground here is my code

import PlaygroundSupport
import UIKit
let vc = HomeViewController()
let navController = UINavigationController(rootViewController: vc)
navController.view.frame = CGRect(x: 0, y: 0, width: 600, height: 600)

if navController.topViewController == vc {
    navController.topViewController!.title = "Home"
    let button = UIBarButtonItem(image: nil, style: .plain, target: nil, action: #selector(vc.tappedNavButton))
    button.title = "HEy click"
    
    navController.navigationItem.rightBarButtonItem = button
    //    button.topAnchor =
}

PlaygroundPage.current.liveView = navController

here is the code for HomeViewController


import UIKit

public class HomeViewController:UIViewController{
    @objc public func tappedNavButton(){
        
    }
    
    public override   func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .systemPink
    }
}

here's the output

question from:https://stackoverflow.com/questions/66056626/not-able-to-add-uibarbutton-live-playgrounds

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
248 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...