first-responder

Find View that is the firstresponder

↘锁芯ラ 提交于 2019-11-29 19:06:34
问题 I would like to get the view that is the first responder, currently I have a UITableView that contains UITextFields, using a method: -(UIView*) findFirstResponder { } I would like to be able to get the view that is the firstResponder and then do something with that view. Any ideas? 回答1: All I had to do was @implementation UIView (FindViewThatIsFirstResponder) - (UIView *)findViewThatIsFirstResponder { if (self.isFirstResponder) { return self; } for (UIView *subView in self.subviews) { UIView

How to detect when NSTextField has the focus or is it's content selected cocoa

隐身守侯 提交于 2019-11-29 07:19:37
I have a NSTextField inside of a NSTableCellView, and I want an event which informs me when my NSTextField has got the focus for disabling several buttons, I found this method: -(void)controlTextDidBeginEditing:(NSNotification *)obj{ NSTextField *textField = (NSTextField *)[obj object]; if (textField != _nombreDelPaqueteTextField) { [_nuevaCuentaActivoButton setEnabled:FALSE]; [_nuevaCuentaPasivoButton setEnabled:FALSE]; [_nuevaCuentaIngresosButton setEnabled:FALSE]; [_nuevaCuentaEgresosButton setEnabled:FALSE]; } } but it triggers just when my textfield is begin editing as this says, I want

Change UITextField background when editing begins

强颜欢笑 提交于 2019-11-29 02:53:03
问题 I'd like to change the background image of a UITextField when it becomes the firstResponder to show the user that it has focus, similar to the :active or :focus pseudo-classes in CSS. I'm guessing that I may need to do this programmatically; so any help is greatly appreciated. -Giles 回答1: You might as well use the UITextFieldDelegate methods (IMHO, easier to maintain than key-value observers): #pragma mark - #pragma mark UITextFieldDelegate methods - (BOOL)textFieldShouldBeginEditing:

iOS unit test: How to set/update/examine firstResponder?

久未见 提交于 2019-11-29 02:20:36
问题 How do you write first responder unit tests? I'm trying to write a test to confirm that a method advances focus to the next text field. controller is a descendant of UIViewController . But this exploratory test fails: - (void)testFirstResponder { [controller view]; [[controller firstTextField] becomeFirstResponder]; STAssertTrue([[controller firstTextField] isFirstResponder], nil); } The first line causes the view to be loaded so that its outlets are in place. The text fields are non-nil. But

How to activate next UITextField in a UITableView?

与世无争的帅哥 提交于 2019-11-28 21:29:28
问题 I am using this other SO answer for adding UITextField s to my UITableViewCell s. However, I am now at a loss how I can let the user focus on the next item by using the next button. Any hints? 回答1: Try assigning a tag to each UITextField. Once the Next button is pressed, calculate the next tag and use [[UIView viewWithTag:nextTag] becomeFirstResponder] to change the focus to the next text field. 回答2: This worked well for me, would have to be tweaked to fit your needs though: #pragma mark -

iOS app “next” key won't go to the next text field

回眸只為那壹抹淺笑 提交于 2019-11-28 16:30:58
I have a simple scene (using storyboard in IB) with a Username and Password text box. I've set the keyboard to close when you are on the Password text field but can't get the next(return) button to work on the Username to switch the focus (or First Responder) to the Password text box. I'm closing the keyboard while on the Password text field like this: - (BOOL)textFieldShouldReturn:(UITextField *)theTextField { if (theTextField == self.textPassword) { [theTextField resignFirstResponder]; } return YES; } I know it is something similar to this but just can't nail it down. The return key doesn't

Keyboard doesn't dismiss even when a UIResponder object resigns it's first-responder status

人走茶凉 提交于 2019-11-28 06:23:25
问题 I managed to customize the UIAlertView putting two UITextFields as subviews inside of it but in doing so somehow the keyboard broke. When I try to dismiss it resigning the first responder it doesn't do anything just stays there. Here's my code, well, only relevant parts (this is what I put in a UIAlertView subclass): #pragma mark - #pragma mark UIView - (void)layoutSubviews { [super layoutSubviews]; NSArray *subviews = [self subviews]; UIView *backgroundView = [subviews objectAtIndex:0];

How to detect when NSTextField has the focus or is it's content selected cocoa

最后都变了- 提交于 2019-11-28 00:54:23
问题 I have a NSTextField inside of a NSTableCellView, and I want an event which informs me when my NSTextField has got the focus for disabling several buttons, I found this method: -(void)controlTextDidBeginEditing:(NSNotification *)obj{ NSTextField *textField = (NSTextField *)[obj object]; if (textField != _nombreDelPaqueteTextField) { [_nuevaCuentaActivoButton setEnabled:FALSE]; [_nuevaCuentaPasivoButton setEnabled:FALSE]; [_nuevaCuentaIngresosButton setEnabled:FALSE]; [

“First Responder” - Did I get that right?

别来无恙 提交于 2019-11-27 17:51:24
Let me summarize this shortly: A "First Responder" in a nib file is an object, which represents the UI control element that has the user's focus. So if the user clicks on a control, the nib sets that clicked UI control as First Responder. In my app I could make an outlet to that "First Responder" from the nib, so that I could for example send a message "make red font color" to whatever the user has activated by clicking. And then, if this First Responder UI control does not understand that message, the message gets passed up in the responder chain, until a parent element or grandparent (and so

Cannot set searchBar as firstResponder

为君一笑 提交于 2019-11-27 12:01:41
I have a searchBar I'm setting in a tableviewcontroller. i've referenced this similar question UISearchBar cannot become first responder after UITableView did re-appear but am still unable to set it as first responder. In .h file: @property (strong, nonatomic) UISearchController *searchController; @property (strong, nonatomic) IBOutlet UISearchBar *searchBar; In view didload: self.searchController = [[UISearchController alloc]initWithSearchResultsController:nil]; self.searchController.searchResultsUpdater = self; self.searchController.dimsBackgroundDuringPresentation = NO; self