我已这样链接navigationController
和tabBarController
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let viewController = mainStoryboard.instantiateViewController(withIdentifier: "TabAction") as UIViewController
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = UINavigationController(rootViewController: TabBarController())
self.window?.makeKeyAndVisible()
let navigationController = UINavigationController.init(rootViewController: viewController)
UIApplication.shared.keyWindow?.rootViewController = viewController
self.window?.rootViewController = navigationController
self.window?.makeKeyAndVisible()
视图控制器中的barbutton项目的代码:
super.viewDidLoad()
// registering table
recruitmentDbView?.register(UINib(nibName: "recruitmentDashboardCell", bundle: nil), forCellReuseIdentifier: "CustomCell")
// setting colour to navigation bar
self.navigationController?.navigationBar.barTintColor = UIColor(red: 18/255, green: 41/255, blue: 50/255, alpha: 1)
// setting barbutton items on navigation bar
let rightFilterBarButtonItem: UIBarButtonItem = UIBarButtonItem(image: UIImage(named: "FilterIcon"), style: .plain, target: self, action: nil)
rightFilterBarButtonItem.tintColor = UIColor.white
let rightSearchBarButtonItem: UIBarButtonItem = UIBarButtonItem(image: UIImage(named: "SearchIcon"), style: .plain, target: self, action: nil)
rightSearchBarButtonItem.tintColor = UIColor.white
self.navigationItem.rightBarButtonItems = [rightFilterBarButtonItem,rightSearchBarButtonItem]
self.navigationItem.leftBarButtonItem?.isEnabled = true
self.navigationItem.backBarButtonItem?.isEnabled = false
let leftBackBarButtonItem: UIBarButtonItem = UIBarButtonItem(image: UIImage(named: "BackIcon"), style: .plain, target: self, action: nil)
self.navigationItem.leftBarButtonItem = leftBackBarButtonItem
self.navigationItem.title = "Recruit - Dashboard"
let textAttributes = [NSAttributedString .Key.foregroundColor:UIColor.white]
self.navigationController?.navigationBar.titleTextAttributes = textAttributes
}
答案 0 :(得分:0)
尝试此代码:-
let button1 = UIBarButtonItem(image: UIImage(named: "imagename"), style: .plain, target: self, action: selector: #selector(action1)) //
self.navigationItem.rightBarButtonItem = button1
let filterIcon = UIImage(named: "FilterIcon")!
let searchImage = UIImage(named: "SearchIcon")!
let rightFilterBarButtonItem = UIBarButtonItem(image: filterIcon, style: .Plain, target: self, selector: #selector(action2))
let rightSearchBarButtonItem = UIBarButtonItem(image: searchImage, style: .Plain, target: self, selector: #selector(action3))
navigationItem.rightBarButtonItems = [rightFilterBarButtonItem, rightFilterBarButtonItem]
@objc func action1()
{
}
@objc func action2()
{
ProgressViewVc.sharedInstance.showProcessView()
}
@objc func action3()
{
ProgressViewVc.sharedInstance.showProcessView()
}