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
}
}
question from:
https://stackoverflow.com/questions/66056626/not-able-to-add-uibarbutton-live-playgrounds 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…