38207

Set focus and show keyboard programmatically in xcode?

Question:

Here is my coding that UITextField is programmatically created when click on UIButton. But to enhancement is I want to set focus (and show keyboard) to new UITextField when UITextField is being created.

UITextField * txtComp=[[UITextField alloc]initWithFrame:CGRectMake(20,y, 450, 50)]; txtComp.borderStyle=UITextBorderStyleNone; txtComp.delegate = self; txtComp.tag=i+1; txtComp.section=index; txtComp.placeholder = @"New UITextField"; [txtComp becomeFirstResponder];

Above coding work as creating new UITextField but cannot be set focus on new UITextField at all even though <strong>becomeFirstResponder</strong> is set.

Answer1:

-(IBAction)buttonClicked:(id)sender

{

UITextField * txtComp=[[UITextField alloc]initWithFrame:CGRectMake(20,20, 450, 50)]; txtComp.borderStyle=UITextBorderStyleRoundedRect; txtComp.delegate = self; txtComp.placeholder = @"New UITextField"; [txtComp becomeFirstResponder]; [self.view addSubview:txtComp]; [self.view bringSubviewToFront:txtComp];

}

Recommend

  • npm-cli.js not found on git-bash
  • Adding multiple pictureboxes to a form programmatically in vb.net ?
  • AudioUnit framework not found
  • UITextfield not editable-iphone [duplicate]
  • html/hta mutiple file in audio player
  • changes subView frame when rotate
  • How to implement delete functionality for images in different positions in iCarousel iphone
  • iOS: handling of UIGestureRecognisers in UI(Sub)Views
  • How to display a Subclass of UIControl on the screen
  • Autoresize UIScrollView
  • -[NSCFString objectAtIndex:]: unrecognized selector
  • UIScrollView ContentSize.height is 0.0000 by default?
  • UITableView and UILabel repeating
  • Can I put a UIScrollView inside another UIScrollView
  • How to stop the horizontal scrolling programmatically?
  • Trying to use CGContextAddArc… nothing is drawn?
  • Merge two imageViews into one and save iOS swift
  • How to override UserControl class to draw a custom border?
  • String not fitting in label which is in a subview for swift
  • How to load image asynchronously using UIImageView+AFNetworking in ios
  • windowScriptObject method not found on Objective-C code
  • UILabel extra spaces before and after text ios
  • x-axis labels in coreplot not displayed
  • IE11 textarea loses focus if another textarea is disabled
  • Specifying virtual keyboard type for EditText in XML
  • EditText is covered by Keyboard
  • Motorola barcode scanner SDK events C#
  • Outlines on links in IE9 remains when focus is changed
  • jQuery: How to AJAXify WordPress Search?
  • Android device acting as an accessory
  • How to getText() from the input field of an angularjs Application
  • Question about instantiating object
  • NSScanner Loop Question
  • Textfile Structure (tables)
  • Sending data from AppleScript to FileMaker records
  • Eraser for UIBezierPath
  • Compare two NSDates in iPhone
  • KeystoneJS: Relationships in Admin UI not updating
  • AngularJs get employee from factory
  • Load html files in TinyMce