Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 3    Views: 45

NCbuzz
Code is Art
Profile
Posts: 575
Reg: Sep 11, 2013
Lillington, NC
11,100
02/22/15 11:46 AM (9 years ago)

Ultimate Screen Creator -how to makeFirstResponder for a textField on initial load?

Have several textFields on the screen. When the screen loads, I would like one of the textFields to becomeFirstResponder. This would trigger other code to bring the keyboard onscreen- which is my goal to start the screen with the keyboard displayed and a textField selected. Since USC is different then using an XIB, I am not sure how to reference the textField in viewDidLoad?? Might be as simple as calling method textFieldShouldBeginEditing with the correct textField, but can't figure code... -(BOOL)textFieldShouldBeginEditing:(UITextField *)textField { activeField = textField; return YES; }
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
02/22/15 02:04 PM (9 years ago)
Great question! Since this plugin does everything via code, it's not entirely straightforward. However, I did leave room for just such a thing. First, assign the text field a name on the control panel. This way you can identify it. Let's say you give it a name of "userName". Then, at the bottom of the layoutScreen method, write this code: //give the userName field the focus int elementNumber = [self getElementNumberForElementName:@"userName"]; UITextField *thisTextField = [arrayOfElements objectAtIndex:elementNumber]; [thisTextField becomeFirstResponder];
 
NCbuzz
Code is Art
Profile
Posts: 575
Reg: Sep 11, 2013
Lillington, NC
11,100
like
02/22/15 03:31 PM (9 years ago)
Outstanding. Thanks Chris!!
 
NCbuzz
Code is Art
Profile
Posts: 575
Reg: Sep 11, 2013
Lillington, NC
11,100
like
02/22/15 06:22 PM (9 years ago)
Had to put the code in viewWillAppear- and it worked great! For some reason layoutScreen is never called in my app. (Screens have image, textField, button and label elements) Also since I have 10+ screens added the test from other thread to first check for the appropriate screen: (where screenToCheck is the name of the screen I wanted.) NSString *myScreenName = self.screendata.itemNickname; if ([myScreenNickname isEqualToString:@"screenToCheck"]){ ...
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.