Is there anyway to fire the "touch on UITextField" event? Because I would like to place a button that, if pressed, sets the focus on a specific UITextField and starts editing.
Thanks.
Call [textField becomeFirstResponder]; when user pressed on the button you want.
Related
A NSStatusItem has a NSMenu attached, and one of the buttons of the NSMenu opens a NSWindow. Whenever one of these buttons is clicked, the window opens as expected and works properly, but another display of the NSStatusItem is opened.
The NSStatusItem is a clock, so I can see that it is updating correctly. However, the cloned NSStatusItem doesn't have its own menu. If I push the button that makes the window more times, more cloned versions of the NSStatusItem pop up.
Everything works fine except for this.
That's not a whole lot of information to go off of, but there's nothing else I can think of that could potentially help you. I would be happy to provide more information or try something.
EDIT: Every time the button is clicked, awakeFromNib is somehow called, which is why another half-working NSStatusItem happens.
EDIT: Temporary workaround is to put the awakeFromNib method in a dispatch_once.
EDIT: Added method that is triggered when button is clicked, as suggested by #zpasternack
- (IBAction)preferences:(id)sender {
self.windowController = [[NSWindowController alloc] initWithWindowNibName:#"PreferencesWindow"];
[[self windowController] showWindow:self];
}
Is the NSStatusItem contained in the PreferencesWindow nib? That might explain it, since you're loading the nib each time the button is clicked.
Also, is there a reason you need to recreate that window each time the button is clicked? Maybe you could only do it the first time?
- (IBAction)preferences:(id)sender {
if( self.windowController == nil ) {
self.windowController = [[NSWindowController alloc] initWithWindowNibName:#"PreferencesWindow"];
}
[[self windowController] showWindow:self];
}
Please need help : I have two textfield in a view , save button and done button. now first time when I run my app, and type in a textfield the keyboard apperas good and I can save. but when I press done button to exit that view , the keyboard don't appears any more in any other part in my app.
just a shot in the dark here, but try to use
[textField resignFirstResponder];
in the done action
I created a simple cocoa project, and added an NSButton in the window.
Then I added an NSScrollView to the window and hided the NSButton.
However, when I click the scroll view , it is strange that the NSButton action responds!
I guess there is something with the touch event chains, but I failed to find it.
For example, I try to use:
- [NSView becomeFirstResponder];
- [NSView setAcceptsTouchEvents:];
SO what I want is the only the front-most view to become the first responder, and the touch event will not be sent to its superview or so.
Thanks.
This is the view hierarchy:
the scroll view and button are both added to the window view, and the scrollview's frame includes the button's frame. In other words, the button is hidden by the scroll view but still receives click events.
You need to add mouseDown: event in NSScrollView or NSCrollView's View. like this:
-(void)mouseDown:(NSEvent *)theEvent {
NSLog(#"MouseDown in NSView");
}
I'm trying to make a NSWindow close when I click a button for a new NSWindow. I'm not trying to connect the button to make it close because the button is what makes it open. Or can it do both? (i am very new to xcode, please excuse me if this sounds dumb)
Anyway here's my code I tried (no errors popped up or warning):
-(IBAction)switchTo:view2{
[view1 performClose:(id)view1];
}
I have 3 iboutlets ,
IBOutlet NSWindow *view1;
IBOutlet NSWindow *view2;
IBOutlet NSWindow *view3;
I have a button in view1 that opens view2, and a button in view2 that opens view3.
My only problem is when I click the button in view1 to view2, I want view1 to close.
Use [view1 orderOut:nil]; instead of performClose.
You can also connect a button with two selectors. Both will be called.
On the iPhone a UITextField can have a clearButtonMode set to show a small clear button (X) at the end of a text input. Similarly, on the Mac the NSSearchField has a nice clear button on it at the end. My question is - is there a way to enable this on a normal NSTextField?
There's nothing built-in; just use a search field and turn off the magnifying glass:
[[button cell] setSearchButtonCell:nil];
I was looking for the same thing for a multi-lined NSTextField the other day, with no luck so ended up using a button set with no border and to toggle with a small image. set very close to the NSTextField (not on it)
and:
- (IBAction)clearTextViewTex:(id)sender{
[textField performSelector:#selector(selectAll:)];
[textField performSelector:#selector(delete:)];
}
Doing it this way also retained the undo functions, without me having to write any NSUndoManager stuff.