Need help with UITextField

Discussion in 'iOS Development' started by H4CK!NT0SH, Aug 1, 2009.

  1. H4CK!NT0SH

    H4CK!NT0SH Banned

    Joined:
    Jun 28, 2009
    Messages:
    159
    Likes Received:
    0
    Device:
    2G iPod touch
    Hey guys. I'm currently working on an Internet Browser. I have everything set up except the address bar. What's the best way of writing one up? Thanks.
  2. DotSlashSlash

    DotSlashSlash Active Member

    Joined:
    Feb 29, 2008
    Messages:
    1,134
    Likes Received:
    0
    Device:
    iPhone 3GS (White)
    are you asking what is the best way to set up a UITEXTField.. if so

    [OBJC]
    UITextField *textField = [[UITextField alloc] initWithFrame:/*where you want the text field and size of text field)*/]];
    [/OBJC]

    you will also need to set the 'return' button on the keyboard or the text field to something suitable such as 'Go' and make the UIWebView go to the URL in the text field

    to do this you will need to set the delegate of the uitextfield to the class which you are working with.

    First you will need to put this in the interface declaration
    [OBJC]
    <UITextFieldDelegate>
    [/OBJC]
    example:
    [OBJC]
    @interface MainViewController : UIViewController <UITextFieldDelegate)> {

    }
    [/OBJC]
    then you will need to set the delegate of the text field by typing this code after you have created and initialized the text field
    [OBJC]
    textField.delegate = self;
    [/OBJC]

    and finally to catch the the return button press you will need to type out this method
    [OBJC]
    - (BOOL)textFieldShouldReturnUITextField *)textField
    {
    [self /*method which deals with the url*/];
    return YES;
    }
    [/OBJC]
  3. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S
    [OBJC](UITextFieldDelegate)[/OBJC]

    don't you mean

    [OBJC]<UITextFieldDelegate>[/OBJC] ?
  4. DotSlashSlash

    DotSlashSlash Active Member

    Joined:
    Feb 29, 2008
    Messages:
    1,134
    Likes Received:
    0
    Device:
    iPhone 3GS (White)
    thanks for that Chicken *corrected*

Share This Page