NSControl does not work on different Mac - interface-builder

I encountered a very strange problem which I can't solve by myself. I have several UI elements embedded in a NSWindow running as NSBorderlessWindowMask. There are 2 NSSlider, 3 NSButton, a NSComboBox and a NSColorWell.
The application builds for target 10.7 and has sandboxing enabled.
On my development machine every element works as intended. The NSComboBox has a working DataSource and Delegate. The NSColorWell does work too. When I click into the NSComboBox, I can type a text into it. And the NSColorWell opens a color selection.
The moment I hand my app to my beta-tester, the NSComboBox and the NSColorWell can't be edited. This means, that I can add elements to the DataSource of the NSComboBox (via an import) and they may be selected in the dropdown menu, but I can't click into the NSComboBoxCell and write a text. Also no color selection opens when I click the NSColorWell.
I have no clue at all what could cause this behavior. Every element is hooked up correctly and I run the same binary as my beta-tester. The systems both run Mountain Lion in its latest version. I tried creating a NSButton for the beta-tester which runs following methods on the NSComboBox:
[self.nameCB reloadData];
[self.nameCB setEnabled:YES];
[self.nameCB setEditable:YES];
[self.nameCB setNeedsDisplay:YES];
[self.nameCB setFrame:self.nameCB.frame];
[self.nameCB becomeFirstResponder];
[self.nameCB setSelectable:YES];
None helped. I have no clue how to "debug" this behavior. Do you have any suggestions?
Edit: I was able to break it down a bit. When I remove the line
[self.window setStyleMask:NSBorderlessWindowMask];
It works. But I want to get a nice look from removing the titlebar, so it only helps a bit.

As I already edited into my question I found out that this problem is caused by the NSBorderlessWindowMask style on my main NSWindow. I found no other way around it than subclassing NSWindow.
I used this example as a guide. It also works if you just extract the CustomWindow class from the project and add it to your project. Then just set the class of your window in IB to the CustomWindow
I still don't know what caused this problem. If anybody has an idea feel free to leave another answer below please.

Related

NSWindow vs ViewController - OS X - Cocoa

I have been making iOS apps for a while now and I decided that I wanted to start working on making some of them for the Mac too.
The question I have is this: is there any need for an NSWindow, now that developing for the Mac is so similar to iOS??
So I made a simple cocoa application using Xcode and its comes with a storyboard called "Main", just like on iOS.
In that storyboard file, there is a NSWindow which then links to a NSViewController.
Can I get rid of that NSWindow? As I tried setting the NSViewController as the "Initial Controller" and the app still works fine. So whats the point of the NSWindow?
Also, what class links to the NSWindow? I was trying to blur that background of the NSWindow, but I have no way of linking code to the NSWindow.
Sorry for my stupid questions, but I am completely new to development for OS X.
Thanks for your time, Dan.
Those are many questions in one question:
Can I get rid of NSwindow? No, you need a window to show you views.
What is the point of the NSWindow? NSWindow is needed as the window in which the views are displayed and your events are going up the responder chain.
What class is linked to NSWindow? Obviously the NSWindow class, but that is not what you want to know. I think you want to know the delegate that controls NSWindow. This is NSWindowController, although for the MainMenu.xib it is NSAppDelegate.
Hope this gives you the answers you need. An example for working with views in a window is given in this question.
Please, see for further details the windows programming guide, which states:
The NSWindow class defines objects that manage and coordinate the
windows an application displays on the screen. A single NSWindow
object corresponds to at most one onscreen window. The two principal
functions of an NSWindow object are to provide an area in which NSView
objects can be placed and to accept and distribute, to the appropriate
views, events the user instigates through actions with the mouse and
keyboard.
For the question: Can I get rid of NSwindow? I have further comments. In most cases, You need a NSWindow to show view on screen; but in special case you don't, for example, a popup view when you click a NSStatusItem.
So my answer is whenever you need to respond window event such as min/max, you need NSWindow as the view container.

Does the Yosemite (OSX 10.10) feature of xcode live views work with NSView on OSX?

I'm trying to determine if the live view feature works with NSView on OSX 10.10, or is it only iOS at the moment?
It works great with UIView for iOS projects, however I haven't been able to get OSX projects to work.
Yes it does work. You just need to add the same symbols for IBDesignable (before the class interface declaration) and IBInspectable (before the property you want to edit in IB) in the right places in you view class header and be sure your nib or storyboard has the class set properly in tge inspector in IB.
You also need to note that the must be properties and they are somewhat limited in type.
Sometimes IB is still a little flaky about recognizing it right away, so you might need to build or reopen the tab with that nib or storyboard.
Also I would expect your mileage may vary with subclasses of more complex views and remember this only works for objects that are descendants of NSView at some point. No NSCell descendants.

xcode 4.5 UIBarButtonItem Action not responding, built in IB

I've set up a UIBarButtonItem in IB, created the IBAction by dragging from IB to the header file, then just put a simple breakpoint within the action in my source file....... and nothing happens.
I'm using AVCam. I can run the action from a button, but it needs to be done on a toolbar because I'm working with sharekit. I've made toolbars before, and have never had this problem before.
I connected both the toolbar and the barbutton's objects... those both work. I can hide and unhide them freely, but for some reason I just cannot get the action to call.
Anybody got any ideas?
I had a very similar problem with an UIBarButtonItem with outlets not working in Xcode 4.5 - no actions got send when I pushed the button, and the referencing outlet didn't reference to anything.
After some time and googling, I discovered that even more none of all the changes I made to my storyboard did have any effect, but hardcoding the GUI worked.
Finally, emptying Xcode project caches solved my problem - the description how to do this can be found here: How to Empty Caches and Clean All Targets Xcode 4
I had the same problem with Jeff.
For a long time, i tried lots of useless stuff.
Adding selectors programatically , bla bla bla
i also had an UITapGestureRecognizer added on viewDidLoad in order to dismiss keypad.
it was not letting gestures to reach UIView.
Not to UIBarButtonItem Click Event and many more
Not to UITableViewCell Select Event.
This solved my problem:
tap.cancelsTouchesInView=NO;
All of a sudden
UITableViewCell Select started to work
UIBarButtonItem Click event started to work.
My problem was occurring only (7.1)
Not in (8.1)

applicationDidEnterBackground: Issue

I wrote an app that has about 3 different view controllers for each view in the tab bar. I called applicationDidEnterBackground: in each of the view controllers to save all the data in that specific view after the home button is tapped. This runs flawlessly on the iPad simulator, but for some reason, it crashed after trying to edit the data on the iPhone simulator. I thought this is probably an issue with putting the applicationDidEnterBackground: in the view controller, but if that was the issue, then wouldn't it crash on the iPad simulator as well?
I know that I should put applicationDidEnterBackground in the app delegate, but my method looks sort of like this:
- (void)applicationDidEnterBackground:(NSNotification *)notification {
NSMutableArray *array = [[NSMutableArray alloc] init];
[array addObject:firstField.text];
[array addObject:secondField.text];
[array writeToFile:[self dataFilePath] atomically:YES];
}
If I put this in the App Delegate, of course it doesn't recognize firstField or secondField because I did not declare it in header file or synthesize it or anything. If I were to declare everything in the App Delegate, then the outlets in my nib file will fail because each of the File's Owner's class is one of those specific view controllers.
Is the placement of applicationDidEnterBackground: not even my issue since it runs fine on the iPad simulator?
Also, it used to run fine on the iPhone simulator as well. I changed the Image View's background on all of the nibs, then this started happening. I rechecked all my outlets and actions and they match up fine.
EDIT: I fixed it. Turns out I had an extra field that I decided to add to the iPad's nib, but not the iPhone's. I though it would be fine, not the case though. That explains all the weirdness that was going on. I deleted the field in the iPad's nib and everything is A Okay. Phillipe, thank you so much for your help and offer to look it over for me, that is incredibly generous.
I fixed it. Turns out I had an extra field that I decided to add to the iPad's nib, but not the iPhone's. I though it would be fine, not the case though. That explains all the weirdness that was going on. I deleted the field in the iPad's nib and everything is A Okay. Phillipe, thank you so much for your help and offer to look it over for me, that is incredibly generous.

How to create a Menubar application for Mac

EDIT: This is a nice ready-made menubar application here (github source) by this answer.
I was wondering how to make a menubar application, what are the requirements for that to do so?
I saw a simple application for the menubar was to open links using your browser, I want to create something similar to that.
This is the application I like to make similar.
NSStatusItem is what you are looking for. Also add LSUIElement with string value of 1 to your Info.plist to hide it from Dock.
I've found Codebox's Popup to be a great starting point. It is ripe for forking on Github.
Though it works nicely, they do note on their site...
P. S. In Lion, Apple is adding a new class for popovers like in iOS.
So, after OS X 10.7 is released, you would better to rely on native
Cocoa classes where it is possible. In other cases, the Popup project
should still be usable.
BitBar is an application on GitHub that can "Put anything in your Mac OS X menu bar".
It runs shell or other executable scripts (which it calls Plugins - see the many examples in the plugins repo) and displays the results in the menu bar. You can write your own plugin and have it run simply by adding it to the 'Plugins folder'. As well as displaying information, it can also run pre-defined bash scripts interactively from the plugin menus you define.
Since I first posted this answer it's popularity has exploded (52 contributors currently) and there is now even a distributable version with which you can package your own plugins.
A very simple (non-interactive) example to show live Bitcoin price:
As Apple added NSStatusBarButton property to NSStatusItem in Yosemite, we can implement menubar app a lot simpler. I just created a sample project on github.
https://github.com/taichino/PopupTest
FlyCut is another nice open source application that does this. (MIT licensed.) Very handy too, I use it several times a day.
Here's some code that seems like it may be relevant:
// Flycut/AppController.h
IBOutlet NSMenu *jcMenu;
// Flycut/AppController.m
statusItem = [[[NSStatusBar systemStatusBar]
statusItemWithLength:NSVariableStatusItemLength] retain];
[statusItem setHighlightMode:YES];
if ( [[DBUserDefaults standardUserDefaults] integerForKey:#"menuIcon"] == 1 ) {
[statusItem setTitle:[NSString stringWithFormat:#"%C",0x2704]];
} else if ( [[DBUserDefaults standardUserDefaults] integerForKey:#"menuIcon"] == 2 ) {
[statusItem setTitle:[NSString stringWithFormat:#"%C",0x2702]];
} else {
[statusItem setImage:[NSImage imageNamed:#"com.generalarcade.flycut.16.png"]];
}
[statusItem setMenu:jcMenu];
[statusItem setEnabled:YES];
Mail Notifr is another open source Menubar app. It helped me a bunch, especially when I needed to figure out how to implement the open on login. Also available on the App Store.

Resources