Using Interface Builder with Xcode 11 I have created two windows, when I activate the second window it opens as a tab in the main window. How do I change this to start a second window instead of a tab?
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I am using Xcode 11.6 and IB for a macOS app and using a tableview. It has 10 columns. I would like to add the functionality to right click on the header and have a pop menu with the column names to select which columns for the tableview to show/hide. What is the best approach to add this functionality? How is this done?
Is there a way to add an image to a post on the Forum?
Anybody else having problems with app icon on Xcode 12 not showing up for a macOS app?
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.
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?
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?
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
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?
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
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
}
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)!
}
}
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
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?
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