I have not been able to get my NSPopover to detach to a window in my own projects, so to simplify I tried the Apple sample.
I downloaded a fresh copy of the Apple sample project: http://developer.apple.com/library/mac/samplecode/Popover/Introduction/Intro.html
It behaves the same, which is to say I can't drag the window to detach it either.
The project seems to provide all the correct windows and controllers and implements the detachableWindowForPopover: delegate method. However the method is never called.
Does anyone know the secret to detachable NSPopovers?
Found the answer while typing the question…
Mac OS X 10.10 Yosemite has a new delegate method:
(BOOL)popoverShouldDetach:(NSPopover *)popover
The default behavior on Yosemite is NO (should not detach). So delegates must implement this method in order for windows to be detachable. The sample project does not implement this method, so when compiled on Yosemite it will not detach (and also produces several deprecation warnings -- maybe I should have taken that hint that it needs an update).
Adding:
- (BOOL)popoverShouldDetach:(NSPopover *)popover {
return YES;
}
To MyWindowController.m fixes the problem.
Related
I've designed an app that includes support for the touch bar. The touch bar is created in Interface Builder. All code uses Swift's #available checks to make sure that no touch bar code gets executed on macOS prior to 10.12.
The XIB (and app) is set to deploy to 10.10, but when I run my app I still get errors like:
-[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (NSTouchBar)
How can I make sure that decoding the XIB skips the touch bar on macOS prior to 10.12?
You have two choices.
Create the UI programmatically.
Register dummy class pairs for the class name. I'm not sure how to achieve this in Swift, but there is an Obj-C solution here: How to use NSVisualEffectView backwards-compatible with OSX < 10.10?. That answer also provides some extra caution regarding subsequent access of the component.
I reinstalled Xcode 6 after not being able to get the usual ctrl-click help.
Now, whenever I create a new Xcode project for OS X Cocoa Application, the main.swift file is no longer in the supporting files as it used to be. I have 2 partitions and Mavericks on one, Yosemite on the other.
Can anybody please tell me what is going on and how to get around it?
This is my first question, be free to point me out any mistakes in it as well, please.
Thanks
You don't necessarily need a main.swift file. The main (heh) purpose of that file is to call NSApplicationMain(), the function that gets a Cocoa app up and running. But, since every app needs to do that, Apple added a less-boilerplate way of doing things.
Now, you just need to label your app delegate class with the #NSApplicationMain attribute. Then Xcode will build in the right hooks to get your app launched into its main run loop with an instance of your chosen class as NSApp's delegate. The new project templates do this, which is why you don't need a main.swift anymore. (It also frees you from needing to designate the app delegate in a main nib, which is useful for apps using OS X storyboards.)
Of course, if you want to customize your app setup a bit more—say, by running some code before the run loop kicks off, or with a custom NSApplication subclass—you can still create a main.swift file and call NSApplicationMain() yourself. (If you do, be sure to also remove the #NSApplicationMain attribute from your app delegate class.)
I've been trying to develop a status bar app for Yosemite, which is my first OS X app, but when I searched for the document, the NSStatusItem documentation says that almost all of the properties and methods there (e.g. .title, .highlightMode, and .image) are deprecated in OS X 10.10.
So I wonder how I can create a status bar app for Yosemite. I found those documentations from Dash, but it's weird that Apple's documentation doesn't make it deprecated yet. But I know they are usually slow to update the documentation, though I wonder then how and where Dash got those seemingly updated information...
So which is the correct? And if it is deprecated, where can I find the Yosemite-style status bar development resources?
I use Xcode 6.1 Beta and Swift.
In 10.10, NSStatusItem has a new button property which returns an instance of a new class, NSStatusBarButton inheriting from NSButton. This is what should be used instead of setting a custom view on the status item. The deprecated methods of NSStatusItem just forward on to the corresponding method of the button.
See the header files (NSStatusItem.h and NSStatusBarButton.h) for the most current and accurate documentation. The prerelease class references seem to be incomplete. There's some brief, indirect mentions of these changes in the 10.10 AppKit release notes.
After running a mac port self update and installing gnomeui library on osx 10.7, I compiled
OpenCV program with Xcode and the ImShow() function created a window that behaves unexpectedly with flashing and flickering.
In the application output message of Xcode the following is displayed:
opengl support available.
Does somebody know where could be the problem?
Do I need to recompile OpenCV with OpenGL?
Is there anything else I can try to rectify this?
Edit:
i attached a screenshot of the windows Xcode generates, normally this kind of UiWindow with the buttons toolbar is generated by QtCreator. I start thinking the problem derives from Qt being updated consequently to mac port self update.
Probably you don't use waitKey after calling imShow, then the window is created and quickly destroyed. If that's the case simply call waitKey after imShow, then the window is created and waits until you press a key then the window is destroyed.
Okay, so I'm writing an application in Xcode (version 3) for Mac OS X and I'm having trouble with my IBactions. I write them, and connect them to my buttons, but for some reason, they are never called when I click the button. I have double checked and triple checked the connections in Interface builder, but no luck. If you can't help with this, then maybe somebody knows how to manually connect actions to buttons in code? I have found Can you hard code IBActions and IBOutlets, rather than drag them manually in Interface Builder?, but that is for iphone, and what it suggests didn't seem to be in Mac OS X cocoa, only cocoa touch (Not sure though). If anybody could help, I would greatly appreciate it.
UPDATE: I can confirm that this problem is only in one project. New projects work fine.
Have you tried uninstalling your app from simulator/device and do a fresh build and run? I had the same problem and that did the trick for me.
I was running into this same problem and hoped this post had the answer. After some more testing, it seems to do with the signature of the IBAction.
This signature didn't work:
-(IBAction)myAction;
This signature did work:
-(IBAction)myAction:(id)sender;
Adding in the sender parameter seems to do the trick.