add text to beginning of user input in UITextField?

Discussion in 'iOS Development' started by hitman2992, Feb 25, 2009.

  1. hitman2992

    hitman2992 New Member

    Joined:
    Dec 10, 2007
    Messages:
    123
    Likes Received:
    0
    Device:
    iPhone 3GS (Black)
    I am making a web browser and I have stumbled on a problem. to properly get to a webpage you must type in http:// manually or else the browser will just continuously sit there loading. How can i automatically add http:// to the beginning of the user input?
  2. godogshomie

    godogshomie New Member

    Joined:
    Nov 19, 2007
    Messages:
    558
    Likes Received:
    3
    Code:
     
    
    if ([urlText hasPrefix:@"http://"]){
    [self loadSite:[urlText text]];
    }
    else {
    [self loadSite:[NSString stringWithFormat:@"http://%@", [urlText text]]];
    }
    
  3. hitman2992

    hitman2992 New Member

    Joined:
    Dec 10, 2007
    Messages:
    123
    Likes Received:
    0
    Device:
    iPhone 3GS (Black)
    this is not working for me.

    im getting this error

    Code:
    *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UITextField hasPrefix:]: 
  4. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    you're calling [yourfield hasPrefix]

    when it should be

    [yourfield.text hasPrefix

    Please Register or Log in to view images

    "http://"];
    ------------------double post merged------------------
    in case you don't understand why, hasPrefix (and hasSuffix) are from NSString.
  5. hitman2992

    hitman2992 New Member

    Joined:
    Dec 10, 2007
    Messages:
    123
    Likes Received:
    0
    Device:
    iPhone 3GS (Black)
    ah I see silly mistake
  6. hitman2992

    hitman2992 New Member

    Joined:
    Dec 10, 2007
    Messages:
    123
    Likes Received:
    0
    Device:
    iPhone 3GS (Black)
    Im still having some problems with this

    Code:
    *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString URL]: unrecognized selector sent to instance 0x57e3b0'
    2009-02-28 00:59:30.038 GWeb[51726:1503] Stack: (
        2512003339,
        2437062203,
        2512032522,
        2512025868,
        2512026066,
        845491761,
        845163355,
        845163314,
        845491519,
        845490975,
        845490534,
        845490428,
        845490068,
        2283930,
        817575576,
        2512026173,
        2512024616,
        850534100,
        2511504885,
        2511506648,
        850535872,
        2428620949,
        2428620626
    )
    this comes up every time i type in a url with out http://
  7. godogshomie

    godogshomie New Member

    Joined:
    Nov 19, 2007
    Messages:
    558
    Likes Received:
    3
    hmmm well thats how i did it in myFox
  8. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S
    is it possible to make it disregard a prefix ?
  9. hitman2992

    hitman2992 New Member

    Joined:
    Dec 10, 2007
    Messages:
    123
    Likes Received:
    0
    Device:
    iPhone 3GS (Black)
    anyone have any advice
  10. bddckr

    bddckr Active Member

    Joined:
    Dec 2, 2007
    Messages:
    1,434
    Likes Received:
    18
    Device:
    iPhone 4 (Black)
    You should probably learn to understand these error messages.
    You are calling URL to a string. Have a look on your code.

Share This Page