I would like to know if you see any architectural pitfall of this approach.
1/I don’t want to create navigation and toolbar buttons by dragging on storyboard.
2/Using navigation controller to have Navigation bar and tool bar on every View
3/I define butons and action in global appConst.swift and not to force to do it in every ViewController
4/I could use same icon in different ViewControllers and not worry about consistency
5/Make view controller clean of generating buttons
6/I didn’t specify target at creation of button, but when i am using in actual viewcontroller
1/Global file for constants appConst.swift
let workCenterIcon = “WorkCenter.png”
let workOrderIcon = “WorkOrder.png”
let newWrkCtrAction = “newWrkCtrAction”
let newWrkOrdAction = “newWrkOrdAction”
//New work center action
let newWkCtrBtn = UIBarButtonItem(image: UIImage(named: workCenterIcon), style: UIBarButtonItemStyle.Plain, target: nil, action: Selector(newWrkCtrAction ))
//New Work order action
let newWkOrdBtn = UIBarButtonItem(image: UIImage(named: workOrderIcon), style: UIBarButtonItemStyle.Plain, target: nil, action: Selector(newWrkOrdAction))
let spaceBtn = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: nil, action:nil )
2/In any viewController I could use this globally design and maintain icons
override func viewDidLoad() {
super.viewDidLoad()
//TOOL BAR****
//Setup Tool bar buttons
newWkCtrBtn.target = self
newWkOrdBtn.target = self
self.toolbarItems = [spaceBtn,newWkCtrBtn,spaceBtn,newWkOrdBtn,spaceBtn]
…
func newWrkCtrAction()_
{
print(“tapNewWorkCenterAction”)
}
func newWrkOrdAction()_
{
print("tapNewOrderAction")_
}