popUpButton is setEnabled:YES but doesn't allow click - objective-c

my popUpButton is in a window with a group of popUpButtons. If I try to click the 2nd of 4 vertically aligned buttons then the popdown menu will not appear. If I select the 3rd or 4th then the 2nd will now be selectable.
throughout my code the setEnabled on that popUpButton is :YES.
ideas on where to look in my controller?
This is a Objective C/Cocoa Question.

the solution was in the -validateMenuItem code... I wasnt checking for a return value of null somewhere that method and it was logically returning false.

Related

NSDatePicker becomeFirstResponder

I have a data entry form where the first field the user wants to enter is an NSDatePicker.
I wish this field to be highlighted when the user clicks a button (labelled 'New')
I have tried putting in [myDatePicker becomeFirstResponder] but this has no effect.
Can anybody show me how to set the focus to myDatePicker?
Unfortunately, becomeFirstResponder does not work that way.
As mentioned in the docs, you should send makeFirstResponder: to the window that contains the control you wish to become the first responder. In your case the window that holds your NSDatePicker.
becomeFirstResponder can be overridden in a control to return false if you do not want it to become the first responder.
Is your picker linked to a textfield for the output? I have linked custom pickers to my textfields keyboard property before. If the output is set to the textfield, you can make the textfield the first responder and the picker will come up in place of the keyboard.

NSTextView wont update unless I click on it, and it wont focus. Any ideas?

I dont have time right this second to put some sample code, (Ill edit my question tomorrow and add some) but basically what happens is that I have a Window. It works fine usually, but if I use
[myWindow setStyleMask:NSBorderlessWindowMask]
to make it borderless, the NSTextView it contains will stop gaining focus even when you click on it: the ring will never appear, the cursor wont change and the scroll bar will remain gray.
Something else that happens when I make it borderless is that it wont update! I basically have this
[lyricsView setString:someString];
to update the string inside it. The Console marks me no errors, but the string wont appear in the Text View unless I click on it.
All of this stops happening if I remove the line setting the styleMask to Borderless. Any ideas? Suggestions? Comments? Cheers?
Thank You!
Kevin
From the documentation of NSWindow:
The NSWindow implementation returns YES if the window has a title bar or a resize bar, or NO otherwise.
So subclass your window and add this line
-(BOOL)canBecomeKeyWindow
{
return YES;
}

How to focus on an alternate label using cocoa?

I'm still a noob to iPhone development so sorry for the dumb question. I'm creating an app that has a custom numeric keyboard. I have an IBAction 'buttonDigitPressed' that when a digit is pressed it will simply add the digit to a UILabel. Now I have another label that I wish to do the same yet I'm not sure how to gain 'focus' of that particular label. I placed an invisible button over the second label so when pressed hopefully I can call an action to switch the keyboard from the first label to the second label. Yet I have no clue how to accomplish this. Any help would be greatly appreciated!
First of all, having to put an invisible button over the UILabel is skanky. If you want the user to be able to tap a number to mean "next time I hit a digit, append its value to this number", you'll probably be happier if you just use a UIButton right from the start. You can make a UIButton that looks pretty much like a UILabel (i.e. it has no border or background color). To set a UIButton's title in code, call setTitle:forState: with the UIControlStateNormal state. So now you've got tappable numbers, i.e. these UIButtons.
Okay, so now let's pretend you've got, say, three UIButtons. You need to use an instance variable here. So, each button will have an action - let's say doButton:(id)sender. So doButton will store the value of sender (the button that was just pressed) in the instance variable. Now your buttonDigitPressed action just looks in that instance variable to learn which button to append to. That's part of the power of instance variables - they give a method in a class a place to store a value where another method in the same class can get at it.

Objective-C & Interface Builder for Dummies: How do I bind the keyboard?

So, I've been reading through other questions on here and Xcode's documentation, but I'm still a bit confused. Here's the scenario: I have a login screen for my app which has 3 text fields and 1 button. Each text field is bound to have a Return Key in IB: Next, Next, Go.
Now, how do I bind these return keys to actual actions where field 1 moves to the next, then field 2 moves to the next, and last field 3 triggers the button?
Some answers for similar questions suggest the use of textFieldShouldReturn method, but I'm still fuzzy on it. Somehow I can't see how it auto-magically knows what to do without having some kind of binding...
What you need to do is use an IBAction to select the next field when the return key is pressed. To do this, first add a method like this to your UIViewController. Make sure to add the method declaration to your header.
- (IBAction)selectSecondField:(id)sender
{
//_secondField is the IBOutlet to the second field
[_secondField becomeFirstResponder];
}
Build and then go to Interface Builder. Select the first text field and open the connections inspector (⌘2) and drag from the dot next to "Did End On Exit" to your controller with the action. A menu of actions will pop up, select selectSecondField.
You will need an action for each field. Alternatively, you could have one action and use sender to see which field was returned.
There's a handle (in the connections panel) on each text field called "nextfield" or something along those lines? (I can't remember off the top of my head) But if you drag that to the next box, that's how it knows (manually). I think generally it guesses using the X/Y location, but when you need to manually do it, just drag that handle.

want to remove a specific collectionview item with the remove button on that view

I have a collection view item and its prototype view. Within that prototype view I have a little x button. I want that button to remove the exact collection view item that it is on top of.
I can remove a selected item if I click on the space around the x button but if I go straight to clicking the button before clicking the item it will only erase the last selected item.
ideas?
Alright, this should be fun!
Step one: Change the method signature of removeQuartzPlayer to be:
-(void)removeQuartzPlayer:(id)aPlayer;
Where aPlayer will be the player you want to remove. Change the implementation to look something like this:
[quartzPlayerArrayController removeObject:aPlayer];
Where quartzPlayerArrayController would be replaced with the name of the outlet to the NSArrayController that your collection view is connected to. I'll trust that you can figure out how to create an IBOutlet to it, if you don't already have one.
Step one-point-five: remove the connection between the button and the removeQuartzPlayer method in IB.
Step two: Switch to the Bindings pane of the IB Inspector. Select the "Target" binding and make it look like this:
Where the "Controller" popup would be set to whatever object points to your controller.
Step three: Select the "Argument" binding and make it look like this:
Where the "Collection View Item" popup... you get the idea.
Step four: Enjoy your new button, brought to you by the (dark) magic of Cocoa Bindings!
Disclaimer: I haven't actually tested this, but since I have a button that does something similar, it should work. Comment away if I've screwed something up.
Billy