Post

Replies

Boosts

Views

Activity

Create popup menu from right click event
I would like to create a popup menu using swift coding in a macOS app from a right click event using Xcode 11 or 12. Can't seem to find an example of this. I see plenty of IOS examples but none for macOS. Does anyone have an example of this you could share or could show me how this is done. Also, I know how to add a menu to to the View Controller but this allows right click from anywhere in the tableView and I want the popup menu to show when you right click on a row in the table. If anybody is familiar with quicken for Mac I want the same function as it as when you right click on a row in an account register. Here is the code for the right click event:   // right click action     override func rightMouseDown(with theEvent: NSEvent) {     let point = tableView.convert(theEvent.locationInWindow, from: nil)         let row = tableView.row(at: point)         selectedCustomer = custviewModel.customers[row].custNumber!         print(selectedCustomer)         // Add popup menu         print("right click")         print(row)     } I have ask this question on couple of other forums as well as searched for tutorials on this and have come up empty.
12
0
4.5k
Aug ’20
Text Fields don't appear in stack view?
I am using Xcode 11 for a macOS app. When I add a text field(s) to a window and then test, the text field shows up. However when I selected the text field(s) and use the "embed in" button for a stack view they no longer show up. I have even tried this on a test project with one label and one text field and the same thing happens. I must be missing something? Why does this occur?
3
0
2.6k
Aug ’20
Trigger Event from one View Controller to another
I have a macOS app using IB/Xcode 11 with two View Controllers with each having their own custom class. The first controller contains a tableview of my datasource. The second view controller has a detail view to insert new data as in an add function. So, I would like to have an event in the first controller that gets control when the second controller inserts the new data to my SQLite table. How is this done?
4
0
1.1k
Sep ’20
How to identify which NSTextFiled changed?
For a macOS Xcode 11/12 I have the following function in my view controller:  func controlTextDidChange(_ obj: Notification) { So, I want to identify the TextField/SearchField that triggered the notification. I have tired to a few things as well as looked in the debugger at obj object but don't see how to do this? How is this done? Thanks
2
0
383
Sep ’20
How to create a NSSearchField outlet for item in the toolbar?
Using Xcode 11/12 I want to create an outlet for a searchField located in the toolbar in the view controller. Tried control drag to the class for the view controller but that did not work. I know how to create action outlets for toolbar items but in this case I want to create a NSSearchField outlet in my view controller. How is this done?
6
0
975
Sep ’20
Looking for examples of using Color toolbar item?
I am looking for examples to use the default color toolbar item for a macOS app using Xcode 11/12 swift 5. Of course when I click on the color toolbar item the color adjust window window pops up but I don't know how to use it. A simple example of say changing the color of a window based on the selection of a color from the color toolbar item. Thanks
3
0
548
Sep ’20
Unexpected behavior with Xcode 12 split view Controller?
I have the following code in a simple macOS test app using Xcode 12 and IB. It has one split view window and the only code is the code below. I built it to learn how to allow a user to change background colors for a window. This code works fine in a single Window/View Controller. However, when I try the same code in a split Window/View Controller the action code (changeColor) does not get called. Does any body know way this is the case as well as how to get this code working with a split screen controller. class ViewController: NSViewController { 		let colorPanel = NSColorWell() 		override func viewDidLoad() { 				super.viewDidLoad() 				self.view.wantsLayer = true 				self.view.layer?.backgroundColor = NSColor.gray.cgColor 				// Do any additional setup after loading the view. 		} 		@IBAction func changeBKColor(_ sender: NSButton) { 				colorPanel.activate(true) 				colorPanel.action = #selector(changeColor) 		} 		@objc func changeColor(_ sender: NSButton?) { 				print("Layer is", self.view.layer!) 					self.view.layer?.backgroundColor =	colorPanel.color.cgColor }
3
0
423
Sep ’20
Unexpected results from code in extension viewWillAppear
Using Xcode 12 and for a macOS program. I created a test project to run down this error. The test app simply has a window controller/view controller that I added a search tool bar item to. While running searchFieldToolbarItem.view line of code crashes due to nil value. The class hierarchy from the debugger has the baseNSObject at the third level where as I was expecting this a the first level. I have this same code in another app and in debugger it shows baseNSObject at the top level. What am I missing and any ideas how to fix this? import Cocoa var custSearchField: NSSearchField = NSSearchField() class ViewController: NSViewController { 		override func viewDidLoad() { 				super.viewDidLoad() 				// Do any additional setup after loading the view. 		} 		override var representedObject: Any? { 				didSet { 				// Update the view, if already loaded. 				} 		} 		override func viewWillAppear() { 		 guard let toolbar = self.view.window?.toolbar else { 						return 				} 				guard let searchFieldToolbarItem = toolbar.items.last else { 						return 				} 				custSearchField = (searchFieldToolbarItem.view as? NSSearchField)! } }
3
0
578
Oct ’20
This class is not key value coding-compliant error
My environment is as follows: macOS Catalina Xcode 12 StoryBoard Single Window/View Controller - the view controller has custom code to populate a tableView in the View Controller The tableView has 7 columns and is populated from a SQLite table. The tableView displays data for 6 of the 7 columns. On the last column I get the following error: valueForUndefinedKey:]: this class is not key value coding-compliant for the key itemUsedLast. I have searched for information on this error and what I have found is it seems to be saying that for the field itemUsedLast can not find an outlet? But in the case for a tableview the only IBOutlet is one for the entire tableView. Also, the identifiers in the storyboard match the code in the custom view controller. I have completed several tableViews before and have not run into this issue. I have tried several remedies but none resolved this issue. Any thoughts on how to debug this further or resolve this will be appreciated. Thanks
14
0
3.7k
Nov ’20
The Class is not key value coding compliant?
I have a macOS app that contains a tableView. The tableView has 7 columns and is populated from a SQLite table. The tableView displays data for 6 of the 7 columns. On the last column I get the following error:valueForUndefinedKey:]: this class is not key value coding-compliant for the key itemUsedLast. The problem was in the following code:     func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any? {         let identifier = tableColumn?.identifier         //   print(#function,identifier, items[row], identifier?.rawValue)         let str = items[row].value(forKey: identifier!.rawValue)         //  let str = items[row].identifier!)         return str     } When I comment out this code it works fine. Any thoughts on how to debug further?
2
0
3.3k
Nov ’20
How to use NSSpellChecker and NSTextCheckingController?
I have been looking for information on how to implement NSSpellChecker and NSTextCheckingController the last couple of days and have come up empty. Does anybody of some information using these two AppKit API's or even better an example on using them with an IBOutlet text field? I understand Apple use to make available the source code for textEdit app? Does anybody know if this is still the case? Thanks
5
0
1.3k
Nov ’20