Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Manually adding TextField (code only)?

codeLovercodeLover Abu DabiPosts: 4New Users Noob
edited August 2013 in iOS SDK Development
I'm using xCode, and I was winding how can I insert UITextField into my nib file, only by coding?
Any Ideas?
Post edited by Rhade on

Replies

  • ebender001ebender001 MissouriPosts: 173Registered Users @ @
    Although in theory you could edit the descriptive code that backs a nib file, you probably are asking how to add a UITextField programmatically (not directly to a xib or storyboard). If this is not the case, please forgive me. If that is the case, then instantiate a UITextField, set its frame, set its properties (font, text alignment) if you want to customize it, the add it as a subview of your containing view.
    UITextField *myTextField = [[UITextField alloc] init];
    [myTextField setFrame: CGRectMake(100, 100, 75, 21);
    [self.view addSubview:myTextField];
    
  • codeLovercodeLover Abu DabiPosts: 4New Users Noob
    ebender001 wrote: »
    Although in theory you could edit the descriptive code that backs a nib file, you probably are asking how to add a UITextField programmatically (not directly to a xib or storyboard). If this is not the case, please forgive me. If that is the case, then instantiate a UITextField, set its frame, set its properties (font, text alignment) if you want to customize it, the add it as a subview of your containing view.
    UITextField *myTextField = [[UITextField alloc] init];
    [myTextField setFrame: CGRectMake(100, 100, 75, 21);
    [self.view addSubview:myTextField];
    

    Thanks for your reply, but still I have nothing added to my nib when I run the app.
  • codeLovercodeLover Abu DabiPosts: 4New Users Noob
    Thanks a lot, I added some code to make it work, final code it
    UITextField *myTextField = [[UITextField alloc] init];
        [myTextField setFrame: CGRectMake(100, 100, 75, 21)];
        myTextField.borderStyle = UITextBorderStyleRoundedRect;
    
        myTextField.enabled = YES;
         [self.view addSubview:myTextField];
    
  • Duncan CDuncan C Posts: 9,116Tutorial Authors, Registered Users @ @ @ @ @ @ @
    Be careful with terms. A nib file is a file that stores the output from Interface Builder. When you add interface elements in code, you do not add them to the nib, you add them to your view controller's views. Adding views in your code is the exact opposite of adding them to the nib file.

    You are trying to add views through code. You'll confuse the people trying to help you if you word your question that way.

    codeLover wrote: »
    ebender001 wrote: »
    Although in theory you could edit the descriptive code that backs a nib file, you probably are asking how to add a UITextField programmatically (not directly to a xib or storyboard). If this is not the case, please forgive me. If that is the case, then instantiate a UITextField, set its frame, set its properties (font, text alignment) if you want to customize it, the add it as a subview of your containing view.
    UITextField *myTextField = [[UITextField alloc] init];
    [myTextField setFrame: CGRectMake(100, 100, 75, 21);
    [self.view addSubview:myTextField];
    

    Thanks for your reply, but still I have nothing added to my nib when I run the app.

    Regards,
    Duncan C
    WareTo

    widehead.gif
    Animated GIF created with Face Dancer, available for free in the app store.

    I'm available for one-on-one help at CodeMentor
  • codeLovercodeLover Abu DabiPosts: 4New Users Noob
    Duncan C wrote: »
    Be careful with terms. A nib file is a file that stores the output from Interface Builder. When you add interface elements in code, you do not add them to the nib, you add them to your view controller's views. Adding views in your code is the exact opposite of adding them to the nib file.

    You are trying to add views through code. You'll confuse the people trying to help you if you word your question that way.

    codeLover wrote: »
    ebender001 wrote: »
    Although in theory you could edit the descriptive code that backs a nib file, you probably are asking how to add a UITextField programmatically (not directly to a xib or storyboard). If this is not the case, please forgive me. If that is the case, then instantiate a UITextField, set its frame, set its properties (font, text alignment) if you want to customize it, the add it as a subview of your containing view.
    UITextField *myTextField = [[UITextField alloc] init];
    [myTextField setFrame: CGRectMake(100, 100, 75, 21);
    [self.view addSubview:myTextField];
    

    Thanks for your reply, but still I have nothing added to my nib when I run the app.

    Thats what I meant.
Sign In or Register to comment.