I am developing an app that has a tableview and a search view in the view controller and I have this feature working fine. However, I would like to move this search to use a toolbar search item. So, I was looking in the Coca programming for OS X and did not find any section dealing with implementing a search feature in the toolbar.
So, can anyone direct me to any tutorials/books that would help with this?
Yes, I did add a Search Field to the toolbar, but I don’t see a way to create an @IBOutlet in the view controller as I did with the search field in the window. I think the protocol for implementing the search field in the toolbar will require several steps.
The Coca programming for OS X had a section on NSColor protocol and I was looking for a similar tutorial for implementing a search field in the toolbar.
Thanks for the help. That was easy once you supplied the answer… Back to reading Cocoa programming for OS X.
However, I thought I could figure out how to get a hold of the search field it the toolbar. I tried the following code:
override func viewWillAppear() {
if let window = self.view.window as? CustWindow {
print ("\(window.toolBar.identifier)")
let toolBarItem = NSToolbar(identifier: window.toolBar.identifier)
custSearchField = toolBarItem.??????
print(toolBarItem)
}
}
but I did not see how to assign the search field in the toolbar to my variable custSearchField or expose the field to my view controller class. Please advise…
It turns out that there is no need to create a custom window in order to access the toolbar; the standard window already comes with a toolbar property.
The example below assumes that there is only one item in the toolbar: the Search Field.
One instance shows baseNSSearchToolbarItem and then a baseNSToolbarItem before it gets to the baseNSObject while the other one starts with the baseNSObject. Why is this? Any ideas how to fix?