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

Categories

0 votes
245 views
in Technique[技术] by (71.8m points)

swift - Not able to add UIBarbutton ?? live playgrounds

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

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

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...