appkit

How can you implement the NSDocument method -canCloseDocumentWithDelegate:shouldCloseSelector:contextInfo: in Swift?

半腔热情 提交于 2019-12-01 18:31:13
In my application, a NSDocument subclass mission-critical hardware – users really don’t want to close a document by accident! So, I’ve implemented canCloseDocumentWithDelegate… to show an NSAlert and ask before closing. I am now trying to implement this same thing in an application written in Swift. Since the answer comes asynchronously, the “should close” result is passed to a callback on a delegate, and not simply returned. In the documentation for -canCloseDocumentWithDelegate:shouldCloseSelector:contextInfo: , it says: The shouldCloseSelector callback method should have the following

NSTextField placeholder text doesn't show unless editing

て烟熏妆下的殇ゞ 提交于 2019-12-01 13:54:23
问题 I set the placeholder text of my NSTextField in Interface Builder, but the placeholder text doesn't show until I click inside the text field to edit it. Anyone else having this issue? Thanks EDIT: Screenshots. Here's what the field looks like when I'm not editing it: Not editing http://cl.ly/2a0R1h1p2A082g1t1b3q/Screen_Shot_2011-04-01_at_6.51.25_PM.png And this is what it looks like when I'm editing it: Editing http://cl.ly/1c2d1U233R3j3k0M2E2Q/Screen_Shot_2011-04-01_at_6.51.32_PM.png 回答1:

How to make an alert controller in mac using swift

人盡茶涼 提交于 2019-12-01 12:13:05
I am new to Swift, and I'm trying to make a score collected program for Mac OS X. I do know about Swift programming on iOS, but I don't know that much about OS X Swift. So I wrote a program for OS X. I almost finished it, but i want to know how to make alert controller in mac using swift. I know how to do it on iso but i don't know how to do it on OS X and also i want to know how to use .isEmpty in OS X. import Cocoa class ViewController: NSViewController { @IBOutlet var Maths: NSTextField! = NSTextField() @IBOutlet var Science: NSTextField! = NSTextField() @IBOutlet var English: NSTextField!

What is responsible for releasing NSWindowController objects?

人走茶凉 提交于 2019-12-01 11:20:56
Lets say I display a window like so: [[TBAddTaskWindowController new] showWindow:self]; Where is the TBAddTaskWindowController object meant to be released? Is the generic solution to call [self release] in windowWillClose? It doesn't feel right to have any other object "own" the window, because it's meant to exist until the user closes it. The same code that instantiated the window controller by sending the new message to the class, just the same as if it had done it by alloc and init messages. Peter N Lewis Yes, a common way to do release the window controller is with: - (void)windowWillClose

What is responsible for releasing NSWindowController objects?

限于喜欢 提交于 2019-12-01 09:03:12
问题 Lets say I display a window like so: [[TBAddTaskWindowController new] showWindow:self]; Where is the TBAddTaskWindowController object meant to be released? Is the generic solution to call [self release] in windowWillClose? It doesn't feel right to have any other object "own" the window, because it's meant to exist until the user closes it. 回答1: The same code that instantiated the window controller by sending the new message to the class, just the same as if it had done it by alloc and init

Resizing window to view controller size in storyboard

此生再无相见时 提交于 2019-11-30 18:23:40
I am working on Xcode 6.1.1 on OSX 10.10. I am trying out storyboards for Mac apps. I have a NSTabViewController using the new NSTabViewControllerTabStyleToolbar tabStyle and it is set as the default view controller for the window controller. How do I make my window resize according to the current selected view controller? Is it possible to do entirely in Interface Builder? Here is what my storyboard looks like: The auto layout answer is half of it. You need to set the preferredContentSize in your ViewController for each tab to the fitting size (if you wanted the tab to size to the smallest

How do you use the dark vibrancy on an NSWindow?

六眼飞鱼酱① 提交于 2019-11-30 12:21:17
问题 What is the correct way to use the Vibrant Dark ( NSAppearanceNameVibrantDark ) or Vibrant Light ( NSAppearanceNameVibrantLight ) modes with an NSWindow ? I'm building an application and would like to offer the new Vibrant Dark appearance as an option for the main application's NSWindow . The window itself is a pretty straight forward window with an NSToolbar across the top and a scroll view as the main content area. There's plenty of information from Apple on using the new vibrancy

How to get the physical display resolution on MacOS?

六月ゝ 毕业季﹏ 提交于 2019-11-30 09:41:50
问题 I'm looking to find the value that "About this Mac" shows (2560 x 1600 on my 13" MBP). I have tried CGDisplayBounds and NSScreen.main, both do not return those values but instead return what is used internal for rendering / measuring. as by Kens suggestion: let modes = CGDisplayCopyAllDisplayModes(CGMainDisplayID(), [kCGDisplayShowDuplicateLowResolutionModes: kCFBooleanTrue] as CFDictionary) as! [CGDisplayMode] for mode in modes { let flags = String(format:"%02X", mode.ioFlags) print("\(mode

View-based NSOutlineView without NIB?

冷暖自知 提交于 2019-11-30 09:38:14
NSOutlineView is a subclass of NSTableView . And currently, NSTableView supports two implementations. Cell-based. View-based. To make OSX 10.8 Finder style side bar ( with automatic gray Icon styling ), need to use view-based table view with source-list highlight style. With NIBs, this is typical job. Nothing hard. (see SidebarDemo ) But I want to avoid any NIBs or Interface Builder. I want make the side bar purely programmatically. In this case, I have big problem. AFAIK, there's no way to supply prototype view for specific cell. When I open .xib file, I see <tableColumn> is containing

Force NSMenu (nested submenu) update for Main Menu of Cocoa App

跟風遠走 提交于 2019-11-30 07:43:54
I have some submenu inserted as Window item submenu of Main Menu I have an instance of my object (let's assume its class name is MenuController) inherited from NSObject and supports 2 from NSMenuDelegate methods: – numberOfItemsInMenu: – menu:updateItem:atIndex:shouldCancel: This instance added as Blue-Object into NIB for awaking at runtime Object from steps 2-3 configured as delegate for submenu (step 1) Now, I can provide submenu content in runtime. Next, I do following: I can add new items or remove old from an array (inside MenuController which contains menu titles) that mapped to real