Tuesday, May 30, 2023
HomeiOS Developmentios - How change BarButtonItem on energetic tabBar

ios – How change BarButtonItem on energetic tabBar

I’ve controller with 2 VC on UITabBarController. And I’ve rightBarButtonItem. How I can Change my rightBarButtonItem, when energetic my secondViewController. My navigationController rooted in SceneDelegate

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, choices connectionOptions: UIScene.ConnectionOptions) {
        guard let windowScene = (scene as? UIWindowScene) else { return }
        let window = UIWindow(windowScene: windowScene)
        window.rootViewController = UINavigationController(rootViewController: StartVC())
        self.window = window

and code of my TabBarController:

import UIKit

closing class MainMoneyCountVC: UITabBarController {
    let names: [String]
    // MARK: - Life Cycle
    init(names: [String]) {
        self.names = names
        tremendous.init(nibName: nil, bundle: nil)
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been applied")
    override func viewDidLoad() {
    // MARK: - Personal Strategies
    non-public func setupUI() {
        view.backgroundColor = .systemBackground
    non-public func settingsNavigationBar() {
        navigationItem.leftBarButtonItem = UIBarButtonItem(picture: UIImage(systemName: "chevron.left"),
                                                           fashion: .plain,
                                                           goal: self,
                                                           motion: #selector(pressedBtn))
        navigationItem.rightBarButtonItem = UIBarButtonItem(picture: UIImage(systemName: "plus"),
                                                            fashion: .plain,
                                                            goal: self,
                                                            motion: #selector(pressedAddExpensButton))
    non-public func settingsTabBar() {
        tabBar.backgroundColor = .systemBackground
        tabBar.barStyle = .default
        let expensesVC = ExpensesVC()
        let merchandise = UITabBarItem(title: "Bills",
                                picture: UIImage(systemName: "doc.textual content"),
                                selectedImage: nil)
        expensesVC.tabBarItem = merchandise
        let balancesVC = BalancesVC()
        let itemsec = UITabBarItem(title: "Balances",
                                   picture: UIImage(systemName: "arrow.left.arrow.proper"),
                                   selectedImage: nil)
        balancesVC.tabBarItem = itemsec
        setViewControllers([expensesVC, balancesVC], animated: true)
    // MARK: - Actions
    non-public func pressedBtn(){
        navigationController?.pushViewController(StartVC(), animated: true)
    non-public func pressedAddExpensButton() {
        navigationController?.pushViewController(AddExpenseVC(names: names), animated: true)



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments