Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9159387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:28:47+00:00 2026-06-17T13:28:47+00:00

I have an textfield which the user types whatever thing they want to Google.

  • 0

I have an textfield which the user types whatever thing they want to Google. When the user clicks done in the Textfield it goes to a new view with an web view. The ISSUE Is when I type something in the textfield the web view is just white (Doesn’t load it to the web view).

 #import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSString *query = [self buildGoogleSearchParameter:self.searchField];
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.google.co/search?q=%@", query]];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [self.webView loadRequest:request];


}

- (NSString *)buildGoogleSearchParameter:(NSString *)searchField
{
    NSArray *unencodedStrings = [searchField componentsSeparatedByString:@" "];
    NSMutableArray *encodedStrings = [NSMutableArray array];

    for (NSString *unencodedString in unencodedStrings)
        [encodedStrings addObject:[self urlEncode:unencodedString]];

    return [encodedStrings componentsJoinedByString:@"+"];
}

- (NSString *)urlEncode:(NSString *)unencodedString
{
    return CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL,
                                                                     (CFStringRef)unencodedString,
                                                                     NULL,
                                                                     (CFStringRef)@"!*'();:@&=+$,/?%#[]",
                                                                     kCFStringEncodingUTF8));
}


-(IBAction)searchdone {

    ViewController *web = [self.storyboard instantiateViewControllerWithIdentifier:@"WebView"];
    web.searchField = searchbar.text;
    [self presentModalViewController:web animated:YES];
}

@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:28:48+00:00Added an answer on June 17, 2026 at 1:28 pm

    The problem is that you appear to be trying to issue loadRequest before you even create the controller with a storyboard identifier of "WebView".

    If you’re trying to present a new modal view with the UIWebView on it, generally, you would add a NSString property in your web view ViewController for the string being searched, say searchField, e.g.:

    -(IBAction)searchdone {
    
        ViewController *web = [self.storyboard instantiateViewControllerWithIdentifier:@"WebView"];
        web.searchField = searchbar.text;
        [self presentModalViewController:web animated:YES];
    }
    

    and then the viewDidLoad for that view controller with the web view would then do the loadRequest building the URL using the searchField property:

    Thus, ViewController.h for the destination view controller might have an @interface that includes not only the UIWebView, but also our new searchField property:

    @interface ViewController : UIViewController
    
    @property (weak, nonatomic) IBOutlet UIWebView *webView;
    @property (nonatomic, strong) NSString *searchField;
    
    @end
    

    And the @implementation in the .m file might be:

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        NSString *query = [self buildGoogleSearchParameter:self.searchField];
        NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.google.co/search?q=%@", query]];
        NSURLRequest *request = [NSURLRequest requestWithURL:url];
        [self.webView loadRequest:request];
    }
    
    - (NSString *)buildGoogleSearchParameter:(NSString *)searchField
    {
        NSArray *unencodedStrings = [searchField componentsSeparatedByString:@" "];
        NSMutableArray *encodedStrings = [NSMutableArray array];
    
        for (NSString *unencodedString in unencodedStrings)
            [encodedStrings addObject:[self urlEncode:unencodedString]];
    
        return [encodedStrings componentsJoinedByString:@"+"];
    }
    
    - (NSString *)urlEncode:(NSString *)unencodedString
    {
        return CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL,
                                                                         (CFStringRef)unencodedString,
                                                                         NULL,
                                                                         (CFStringRef)@"!*'();:@&=+$,/?%#[]",
                                                                         kCFStringEncodingUTF8));
    }
    

    Note, webView is the name for my IBOutlet for my UIWebView. You should replace that with whatever is appropriate for your project.

    Also notice that I did some url encoding of the search fields. That way you can search for fields with ampersand characters, quotation marks, etc. The easiest way to do that is the CFURLCreateStringByAddingPercentEscapes that you see above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form with a textfield element which when a user starts typing
I have a textfield which displays a result but I don't want it to
I have a textField on my stage named 'adBuy', which when clicked I want
I have a textfield, in which I need the user to type only numeric
I have User, which can be one of three types: Admin, Student, Teacher. Everyone
I have a text field in SQLite database, which I want the user to
I have two text fields which whatever user enters in first text field, it
I have a textfield which takes in full name example: michael peter johnson in
I have a calculator app in which I have a textfield in which if
I have a textField in my application which will be initiated programmatically (textField.setText() )

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.