Inside my .xib, I've placed an NSColorWell inside an NSView, and connected an IBAction in the controller to the NSColorWell's Sent Actions (via File's Owner). I figured I would respond to a click in my controller and send activate to bring up the NSColorPanel.
But unlike other my controls, I'm not getting the IBAction called. Clicking invokes a drag action on the color. I noticed this control doesn't derive from NSActionCell (like all my other controls). What's the proper control that is supposed to be used to both display a color and invoke the NSColorWell when clicked?
(note: this is Xcode/IB 3.2.x)
You listed both osx and ios in the tags, but I'm guessing this is an OS X problem.
There is a "Bordered" checkbox in IB's Attributes Inspector for NSColorWell. This toggles between a button-style color well, which is what you're asking for, and a color well which you can only drag a color swatch from. Make sure that's checked and you'll get the action like you're expecting.
Related
I am attempting to set the key equivalent of a NSButton in a NSWindow. I am using the following code in my view controller's class:
someButton.keyEquivalent = "\r"
However, when I run the application, pressing the key will not perform the button's action but play the system funk sound.
The window which contains this NSButton is presented as a window (not a sheet) using a modal NSStoryboardSegue. If I use the same code and configuration in my initial window, the key equivalent performs correctly. Would the type of presentation cause this problem? Thanks.
EDIT
Turns out this may be a possible bug. Key equivalents will not work when a title bar is deselected in the IB. I am now attempting to find a way to keep this selected with the same window appearance. Keeping the option selected and using the titlebarAppearsTransparent property on NSWindow, I have successfully removed the title bar but now I am unsure how to remove the window border. Any ideas?
Do you happen to have the title bar disabled in your window? There's some unexpected behavior (hesitate to call it a bug) where keyboard events are ignored in a modal window if the title bar is disabled (even though the title bar isn't used in sheets).
What is the point of ever setting a button as an outlet? I am following a tutorial and the teacher didn't really mention why he set a button as an outlet. A button is suppose to do an action/call a method and so we set it as an IBAction.
He sets the button as an outlet and then proceeds to change the text of the button through Xcode in viewDidLoad, but why not just keep it as an IBAction and change the text by using setTitle: forState:UIControlStateNormal ?
Isn't a button suppose to cause an action by definition?
in some logic cases you would need to change the behaviour of the button , e.g. upon invoking an action (triggered by other event )you will need to disable it or change its backgroundColor or text.
you don't have to set at all times , but in many cases it is really useful
My Setup
I have a ViewController, where users type some sort of text in there. Call it InputViewController.
I have a UIView (in a separate class), where I draw a navigation bar that has a gradient (I override drawRect for Core Graphics, hence I need to to have in a separate class) which has a button. The button takes you to a MapViewController, which allows you to add a location tag to your input. Once a location tag is added, I would like to change the button's image.
My Problem
Once the button is tapped, I need to send the user's input to the MapViewController, where a delegate is also implemented and will pass back some information back to the InputViewController. The issue here is that the button resides in the separate UIView. One way to do this is pass the UIView the information once they are set, which in turn would be passed to the MapViewController once the button is tapped. The problem here would be the delegate as the delegate needs to return to the InputViewController and not the `UIView.
I was wondering if its possible to move the UIView into the InputViewController, including the drawRect method for that view. If so, how can I do that? If not, what are other ways/suggestions I can do to have the above set up?
I guess you need to use NSNotifications for sending messages to your classes. See this.
I have a transparent NSWindow that follows the user's screen everywhere he goes (the NSWindowstays in front of every app, no matter what, even fullscreen apps).
In that NSWindow i have a mouseDown event that shows a popup. Let's say i'm on safari in fullscreen mode and i have my Window in front of it, i click on safari and i click again on my Window: nothing happens, the mouseDown doesn't occur. I have to click again so the mouseDown event is triggered.
How can i force my NSWindow to be always active so i don't have to click it 2x to trigger the mouseDown when i click on a background app and click in my window again?
Thank you!
I'm not sure if this is exactly what you want (it's not quite a window wide setting), but, from the documentation:
By default, a mouse-down event in a window that isn’t the key window
simply brings the window forward and makes it key; the event isn’t
sent to the NSView object over which the mouse click occurs. The
NSView can claim an initial mouse-down event, however, by overriding
acceptsFirstMouse: to return YES.
The argument of this method is the
mouse-down event that occurred in the non-key window, which the view
object can examine to determine whether it wants to receive the mouse
event and potentially become first responder. You want the default
behavior of this method in, for example, a control that affects the
selected object in a window.
However, in certain cases it’s
appropriate to override this behavior, such as for controls that
should receive mouseDown: messages even when the window is inactive.
Examples of controls that support this click-through behavior are the
title-bar buttons of a window.
Or you could try fiddling with
- (void)sendEvent:(NSEvent *)theEvent
and see if you can handle events in a custom way.
If you add a borderless NSButton instance to your window's view and set your image as the button's image (and as its alternate image, to make it more beautiful), it will work out of the box: Just connect the button's action method to your app delegate (or the object where you want to process the click action). A click on the image (i.e. the button) will then trigger the button's action method, no matter which window is active.
This worked for me, hope that will be helpful, This will keep your window always on Top of all applications
[self.window makeKeyAndOrderFront:nil];
[self.window setLevel:NSStatusWindowLevel];
I think what you really should do is use an NSPanel (a floating palette -- a special kind of NSWindow) that will do exactly what you want in a way that's consistent with the OS rather than trying to fight intended behavior.
Here's the NSPanel documentation:
https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/nspanel_Class/Reference/Reference.html
And here's some helpful and pithy information:
http://cocoadev.com/wiki/NSPanel
By default, an NSPanel will disappear when the application is inactive, but you can turn this off.
I apologize for not laying it out more fully ... pressed for time.
Edit:
Note that you can probably get your window to behave as desired simply:
"The NSView can claim an initial mouse-down event, however, by overriding acceptsFirstMouse: to return YES."
https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/EventOverview/HandlingMouseEvents/HandlingMouseEvents.html
You'll need to do this with any NSView subclass to skip the "activation click".
Sorry for the complicated title, but it's hard to explain.
This is the hierarchy I have:
Custom View
Custom View
Push Button
Box
WebView
WebView
The way my code works, is that the 'Box' has a 'setContentView' to one of the 2 WebViews shown above. So basically the Box can have a different WebView at any time.
I have the Push Button, which I want to assign to 'Go Back' on the WebView. But I need this button to 'Go Back' on the WebView which is within the Box.
So whenever the WebViews are switched around, the Push Button should link itself to whichever WebView is in the Box, and visaversa.
Is this even possible?
Thanks in advance everyone!
If you had an IBOutlet for your box (called theBox) defined in whichever custom view your button's action method is in, you can just use this in that action method:
[(WebView *)self.theBox.contentView goBack];
So whenever the WebViews are switched around, the Push Button should
link itself to whichever WebView is in the Box, and visa versa.
Why not use a more conventional arrangement? Make the view controller the button's target, and have the action in the view controller take whatever action is appropriate. In this case, that would be adding the appropriate web view to the box.
Views normally don't know anything about how the application works. They just do what the controller tells them to do.