iPhone Coding – Learning About UIWebViews by Creating a Web Browser

December 19th, 2008 Posted by: (ELC) - posted under:Tutorials

Wow! It has been a long time since my last tutorial… As I wrote in my last post, I had to take a break due to my wife having our baby.  But, now I’m back and have a great tutorial for you guys.  

Today I will be showing you how to work with a  UIWebview to create a basic web browser.  Here is a screenshot of the app we are going to create.

screenshot_02

Create a View-Based Application

Ok, so let’s get started.  Start by opening up Xcode and click File -> New Project.  Next select View-Based Application and click Choose… Name this project something like iCodeBrowser and click Save.  

screenshot_03

screenshot_04

Now we are ready to begin coding…

Create IBOutlets and IBActions

Before we create the interface for our web browser, we need to establish the IBOutles and Actions to interface with the UI elements in code.  Start by opening up iCodeBrowserViewController.h and add the following code:

screenshot_06

Let’s take a look at this code line by line.  The first thing we added was the <UIWebViewDelegate> to the end of our interface declaration.  This is telling the app that this class will be the delegate for our UIWebview.  

What does it mean to be the delegate you ask? Great question… A delegate is like a handler.  It is responsible for implementing certain methods in order to handle events sent by the object they are the delegate for.  So in our example, we are simply saying that we will implement some of the functionality of the UIWebView.  This is needed so we can capture certain actions of the UIWebView such as a click on a link or so we can tell when a page has started/finished loading.  If it’s still unclear, ask me clarifying questions in the comments section.

Next, we see our 3 lines of declaring IBOutlets.  These are the UI elements that we will be interacting with.  In case you didn’t know, the UIActivityIndicator is the little spinner/loading animation that you see on various apps when content is loading.  We will be using this to show that a page is currently loading.

Following this code, there are 3 IBActions.  IBActions are functions that get called in response to a user interaction with the application (such as tapping a button).  For our basic browser, we are only offering 3 types of functionality.  gotoAddress which will take a user to the address they type in the address bar and goBack/Forward should be pretty self explanatory.  

Creating the User Interface 

Now, let’s create the interface using Interface Builder.  I am going to be showing you how to do this in the video below.

 

Implementing the IBActions

Now that we have our interface, let’s make the app function.  We need to implement our methods.  Open up iCodeBrowserViewController.m and add the following code.

screenshot_01

We need to synthesize our properties to allow us to interact with them.  Synthesizing automatically creates “getter” and “setter” methods for our properties.  Next, let’s implement the viewDidLoad method.  This is where we will be loading our “homepage”.  Add the following code to the viewDidLoad method.

screenshot_08

The viewDidLoad method gets called automatically by our application whenever this view first loads.  We can know for sure that it will get called, so we can put our initialization code here.

The first thing we see is the urlAddress string.  This will be our “homepage”.   You can change this to any address you wish to start with.  Next, we build a URL object with our string.  We need to do this so we can make a web request.  Following this, we build our web request and load it into the webView.  This will display the homepage inside of our webview.  Finally, we set the text of the address bar to the homepage address.  This part is more for aesthetics to let the user know what page they are on.

Next, we implement the method that we connected to the UITextField’s DidEndOnExit method gotoAddress.  Add the following code:

screenshot_09

This is similar to the code we wrote in the viewDidLoad method, except for the fact that we are getting our URL string from the address bar.  This method gets called when the user presses the “Go” button on the keyboard.  The last thing to note here is we call the [addressBar resignFirstResponder] method.  This simply tells the app to hide the keyboard when this method gets called.

The implementation of our Back and Forward methods are pretty easy.  Go ahead and add the following code.

screenshot_10

UIWebViews are pretty cool because of the functionality they offer us built right in to them.  We simply call [webView goBAck] to go back and [webView goForward] to go forward.  This greatly simplifies the interactions with the webview.  If we were to code that functionality from scratch, we would have to create a stack of URLs and continually push and pop them off the stack to keep track of where we need to go.  Thanks Apple for not making us implement this.

Finally, we need to implement the delegate methods for UIWebview.  These methods allow us to write our own code to respond to actions by the UIWebview.  The first methods we will implement are the webViewDidStartLoad and the webViewDidFinishLoad methods.  We will use these to show and hide the activity indicator. Add the following code:

screenshot_11

So when the request is first made for a ULR (before the page starts loading) the webViewDidStartLoad method gets called automatically.  We use this opportunity to start our activity indicator to let the user know the page is loading.  If you don’t have something like this, it simply feels like the app is frozen when in fact, it’s just loading the page.  Finally, the webViewDidFinishLoad method gets called when the page is fully loaded.  After this, we can stop the indicator (and it automatically hides itself).

The very last thing we need to do is define what happens when a user clicks on a link. Add the following method:

screenshot_13

This method gets called automatically whenever the user clicks a link.  This method can be very useful if you want to make a native iPhone application that integrates with a web app.  You can use this method to trap the user’s clicks and have your application respond to web links that get clicked.  In our case, we need it to do 2 things.  The first is to set the text of the address bar to the URL of the link that was clicked on and to load that address into the webview.

One thing to make note of: We do a check to see if the URL scheme is “http”. This is to ensure that the user typed http before their URL.  You can add an else statement here that auto prepends the http if the user did not add it.  This would allow you to type in a url such as “icodeblog.com” rather than having to type “http://www.icodeblog.com”.  I chose to omit it for this tutorial.

Remember, all of this added functionality of a UIWebView can only be gotten if you tell your class that it implements the UIWebViewDelegate protocol as we did in our .h file.

The app should be complete! Click on Build and Go to see this baby in action.  Remember, you must put “http://” in front of your URL’s.  

I hope you have enjoyed this tutorial.  If you have any questions or comments, feel free to leave them in the comments section of this post.  You can download the source here . Happy iCoding!

 

 

  • Dan

    Congratulations on the new Baby!

    Can’t wait to dive into this tutorial, looks like quality work yet again!

  • Pingback: iPhone Coding - Learning About UIWebViews by Creating a Web … : businessuu

  • http://samgreen.info Sam Green

    Congrats!

    I was so glad to see some activity from you in my feed reader. Well written and concise. Thanks again for all the hard work. You’ve definitely been an asset to me, and probably a great majority of the iPhone development community. Keep it up!

  • Joe

    Congrats on the baby and thanks so much for all of you wonderful tutorials… I had begun to wonder if something happened to you, but I am glad to see you are back! Hope everything is well. Can’t wait to see more tutorials.

  • JItesh

    Thanks for the tutorial …

    The tutorial worked perfectly, but I got stuck in one problem,

    I try to open gmail using this program and the gmail page was open successfully…..

    now when I clicked inside the text box(i.e. Username field) of gmail the UIWebView automatically shifted up side

    and the keyboard which should be appeared at the bottom also get shifted upper side and I am able to see only the last three buttons.

    by scrolling I get the view back to normal position but … what about keyboard..??

    I can’t understand why it is happening like this.

  • Mike

    I’ve been enjoying your tutorial. I’m running into a problem. I’ve done the TODO list project and tried to expand on it and try to put a tab bar. Tab bar 1 grabs Todo1 table from sqlite and Tab bar 2 grabs todo2 table. The problem is, everytime I add a new entry into Tab bar 1 and then close the application by clicking home… when i relunch the app… it also creates an blank entry on Tab Bar 2. I need help. Is there a way I can send you the zip file of my project? If not, is it possible for you to create the TODO List project but with tab bars so I can learn. Please =). Thanks in advance.

  • Kieran

    Is there anyway to force the uiwebview to only show part of a page. For example I have a table on my webpage and want to show it in a uiwebview but I don’t want the user to be able to navigate the rest of the page, only to see that part.

  • Fredrik

    Hi,

    The line “@implementation iBrowserViewControll” should be “@implementation iCodeBrowserViewControll”.

    At least I needed to change this to get things working ;-)

  • bobcubsfan

    Had to modify this method:

    -(void)webViewDidStartLoad: (UIWebView *) webView
    {
    activityIndicator.hidden = NO;
    [activityIndicator startAnimating];
    }

    adding activityIndicator.hidden = NO;

    to get it to work.

    Otherwise, thanks for the tutorial “dad.”

  • http://www.freshapps.com Brandon

    @Fredrik

    Lol copy and paste error…

    @Bob, what was the error that required u to add that code?

    @kieren
    Make an iphone formatted page on ur site

    @Mike

    read the tut on tab bars

  • http://rschoenburg@schoenburg.com Bob Schoenburg

    No error. Activity indicator did not display. Thanks for the tip about using a fixed spacer in the tab bar. I also used a variant of the indicator to hide the indicator in my app.

    -(void)webViewDidFinishLoad: (UIWebView *) webView
    {
    // Load finished, hide the activity indicator in the status bar
    [UIApplication sharedApplication].isNetworkActivityIndicatorVisible = NO;
    }

  • iBob

    Thanks for the nice tuto…
    But i need to say that i preferred and loved previous video tutorials with the full guide on it… :)
    Thanks a lot.

  • http://diendanapple.vn Tommy

    i had finished your tut well

    it ran on iPhone Simulator but when i winscp it to iphone then it crash , it back to homescreen

    what’s it wrong ?

  • http://www.freshapps.com Brandon

    @Tommy

    Why not just use XCode to transfer it to the iPhone. I am not sure about using winscp for this task.

    @iBob

    I’ll do both. There are about an even number of people that prefer one style over the other. This tut just had a lot of code writing, so I didn’t want to make a 10 min vid of me writing code…

  • http://www.grupoanfa.com Dunkel

    @Tommy

    You need to sign the app just after you transfer it via winscp, and why you use winscp? aren’t u working on a mac? you can use cyberduck or something like that

  • Ricardo Drouyn

    I noticed that the last step in setting up your view, you connect the webView and the view as outlets to your icodebrowser view controller. Even though it works, this causes a warning in interface builder saying that this setup isn’t supported. Specifically it says the controller has its ‘NIB Name’ property set and its ‘view’ outlet connected. Any idea why im getting this warning?

    Another question I have is for the reasoning behind modifying the mainWindow xib and not the icodebrowser view controller xib. I havent noticed us doing this in previous tutorials.

    That is all, thanks for the great work!

  • http://www.theiphoneguru.org Michael

    Hey! Thanks for the turtorial. I got up to the video, however, i run into a problem there. After you drap the objects onto the window, I cannot link the Events (i.e Did End on Exit) so the iCodeBrowser in MainWindow.xib. That window turns grey and I cannot drag anything into it. Any reason why?

    Thanks!
    ~Michael

  • Mike

    Hey buddy… sorry to bother you and I know this question is for an old tutorial… but here’s the question I have for the SQL tutorial that you have.

    When I add an entry, the segmented controller is set to the value of low when the view is loaded. Lets say, I change the value to Med and save it. When I try to add another entry… the segmented controller is set to the last value… in this case… Med. My question is… how do I reset the segmented controller to Low everytime I add a new value or when the View is loaded? I’ve checked Apple’s docs and can’t find the answer.

  • zword

    I just wanted to know, if you don’t have to set
    “webView.delegate = self;” ?

    Otherwise the UIWebViewDelegate methods won’t be called.
    I was following your tutorial and it didn’t work until I set
    “webView.delegate = self;” in the viewDidLoad method.

  • Moon

    Hi
    Thanks for all your tutorials,at one time I did loose hope of developing something on iPhone but after reading thru these tutorials I am in race again !!.

    One question about UIWebView…How do I clear the contents(or show a blank page) before loading another URL ?

    Thanks again

    Moon

  • Christopher

    Thanks for the Tutorial. One issue though. I got everything to compile with no warnings or errors, but the only thing I get on my screen is the color gray.

    Am I doing something wrong? Should this tutorial be able to run on the iPhone simulator?

  • Rahul

    so how do you change the NSURL or the request to set the http if its not there?

  • Moon

    Rahul: I dont know if you asked me that question ! But if Yes then i have an app where in i have list of items(each row will have a unique URL) so based on what user clicks webview(second view) will show that particular content in deatil.
    I am able to do all these,but after clicking once and coming back to selction view when user clicks on another row …before displaying new link content it shows old content (for few milliseconds and then offcoz the contents of newly clicked url) I just want it to be clear before loading new content each time.

  • Nickel

    Great tutorials.

    Brandon, I have a somewhat personal question about CS at UNM do you think I could get your email so I can ask?
    Thanks.

  • Rahul

    Moon: Well, i was asking brandon a question on how to add the http:// to the beginning of a URL if the user doesnt add it him/herself. But for what you are trying to do…when you click on a row in a table view, if you check if a self.webview==nil and then initialize a new instance of a webview and set it = to self.webview only when it is nil that would be why its happening. So if you clicked on a row and then went back and clicked on another self.webview isnt nil. Just create a new webview, set it, and release it each time…dont check if it’s nil.

    brandon/anyone:default add http:// ???

  • Michael

    I can connect “Did End On Exit” to “I Code Browser View Controller.gotoAddress.”

    However, I cannot connect “New Referencing Outlet” to “I Code Browser View Controller.addressBar.” My only option is “view.”

  • Michael

    I think I figured it out: I mistakenly set type of addressBar to UITextView instead of UITextField.

  • anonymous

    I got the program to compile and run, but my iPhone simulator screen just turns black. The view with the webpage doesn’t load for some reason. I stepped through the code in my debugger and things appear to be executing. Perhaps Christopher and I made the same mistake. Did we miss a step?

    Also note that I downloaded the source code and can get that to run and load the web page. Was a critical step maybe left out of the tutorial, but was actually included in the downloaded source code?

    Please reply to this post and let us know. I’m interested in learning how this works.

  • http://www.designsapling.com Jeremy White

    Brando (or anyone),

    I was also wandering about Ricardo Drouyn’s question:

    Why did we use MainWindow.xib
    instead of iCodeBrowserViewController.xib?

    Thanks!
    Jeremy

  • Rahul

    I used the view instead of the window and mine works fine. I wanted to add in some other functionality. like bookmarks.

    but again…if anyone can tell me if there is an easy way to just default http:// or set it so you dont need it, thatd be wonderful :)

  • http://www.freshapps.com Brandon

    @ Nickel

    it’s brandon@icodeblog.com

  • Jim Z

    Hello,

    I also followed the same directions and all I get is a grey screen. Any ideas?

    Thanks,

    Jim

  • Moakes

    Those of you who only have a black screen appear when you run the application please follow these instructions:

    1.Open up MainWindow.xib in the Interface Builder.
    2.Click “Window” in the “Document Window”.
    3.Click “New reference outlet” and drag it onto “icodeBrowserViewController app DELEGATE” and select “view”.
    4. Build and go :-)

    This should sort it for you.

  • Chris C.

    Dan, If I want my browser to show “splash.pdf” that is a .pdf contained in my App, then how would the url read in he .m file below. Instead of: NSString *urlAddress = @”http://icodeblog.com”;

    Thanks.

    -(void)viewDidLoad {
    [super viewDidLoad];
    NSString *urlAddress = @”http://icodeblog.com”;

    NSURL *url = [NSURL URLWithString:urlAddress];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

    [webview loadRequest:requestObj];
    [addressBar setText:urlAddress];

  • Arg

    Hey, if I’m trying to incorporate this into a project where I have RSS feeds being pulled into other tabs and organized into a table, how do I do that? I don’t even need the address bar or toolbar at the bottom (would be better to have the tab bar at the bottom like I do for the other parts of the app), I just need to be able to load up a webpage within my app

    Any help is GREAT!!

  • Jacob

    Nice tutorial, However, I run into a problem. The application does not rotate to landscape mode. I have overrided shouldAutorotateToInterfaceOrientation as follow

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
    }

    Any idea?
    Thanks

  • http://cimota.com/blog mj

    Everything working fine except the spinning activityIndicator. Doesn’t appear….any ideas?

  • http://www.etherjammer.com/ Chris Anthony

    Thanks for posting this tutorial, Brandon – it’s right up my alley.

    @Jacob, I’m seeing a lot of people having this problem – it seems to be a problem with a recent SDK build. I’ve seen some putative solutions that involve willRotateToInterfaceOrientation, but none of them are working for me! I’ll keep plugging away at it and see if I can come up with a better solution.

    @mj, the spinning activityIndicator works for me (as of yesterday, anyway; I haven’t tried it today). Double-check and make sure that you have the connections applied correctly?

  • Frank

    Hmmm everything works apart from the orientation and the activitymonitor for some reason… just cant figure it.

  • http://N/A download

    hi , how r u???

  • Artful Dodger

    Hi there, thanks for the great tutorials. They are helping me out so much. Clicked build and go on this tutorial and got no errors. Iphone simulator opened up but then I got a black screen on the iphone sim. App did not crash back to springboard or anything. Might be doing something thats so obviously wrong but i just cant figure it out. Any help would be much appreciated.

  • Fred

    Hi,

    I got an error.

    Here’s a image of it:
    http://bildr.no/image/372211.jpeg

    Could you help me? Could you please send the answer to my mail address?

  • Fred

    The picture got really small. Just copy and paste the link. Then it works ;)

  • Pingback: iPhone development Tutorials « The Brook Song - ঝর্ণার গান

  • John

    I am trying to do this with a tab based project, i cant figure out how to connect the webview. there is nothing to connect it to in the xib view. I am trying to add a web browser to a second tab in the tab based layout. that is where ther eis nothing to connect the webview to. all that is there is the “file owner”, “first responder”, and “view”. any ideas?

  • wiegeabo

    My app runs with no errors. But all I get is a gray screen. Nothing seems to load. Any ideas?

  • wiegeabo

    Ok, I figured it out.

    At the end of the video, when setting the referencing outlets for the webview component, Brandon says drag a new referencing outlet to the ICode View Controller and select webview.

    But he doesn’t say do it twice. Once for webview, and again for view. He shows it in the video, but just listening while flipping between windows, it’s very easy to miss.

    Very sneaky Brandon. ;)

  • Tny

    Thanks for a great tutorial! There are a couple of features I’m trying to add to the browser – “Bookmarks” and “History”… I’ve looked everywhere and can’t seem to find an answer. Thanks again!

  • http://ddd Allian

    Hello, can anyone know how to add the http:// string to my NSUrl, I tried a lot of stuff but nothing exist about converting a NSUrl to a NSstring then append an other string then finally convert the whole into a NSUrl.

    please help.
    thanks

  • Pingback: 200ml » 100 Free courses for iPhone Dev

  • Pingback: 100 ресурсов для iPhone-разработчиков - Краковецкий Александр: заметки прогÑ

  • LiveCity

    I am trying to incorporate this into my own application. But I have nothing to connect the activityIndicator too. I have owner, first responder, view. I tried connecting it to the owner since that is the only thing it allows me to. But, I still don’t get an indicator. Plus, the code of:- (void)webViewDidStartLoad:(UIWebView *)webView {
    activityIndicator.hidden = NO;
    [activityIndicator startAnimating];
    }

    - (void)webViewDidFinishLoad:(UIWebView *)webView {
    activityIndicator.hidden = NO;
    [activityIndicator stopAnimating];
    }

    Where exactly does that go? Before the url, after….?

  • LiveCity

    Forgive me…it didn’t work on the simulator, but it does on the phone.

    However, it won’t stop after the page loads. any suggestions?

  • http://mactletico.blogspot.com/ Angelillo

    Great tutorial!

    I’ve followed your steps and everything worked.

    Thank you!

  • UMAD

    Is there anyway to emulate the tap-status-bar to scroll to top? because in the current state it doesn’t work. May be another tutorial? :)

  • doode

    Dude. Some minor enhancements:

    + use a dynamic spacer between the buttons on the lower toll bar.
    + connect the back/forward buttons directly to the goBack and goForward methods on the view! way simpler. Plus you get the original NeXTStep awesomeness of the true target/action paradigm. No middle man of your own custom class – just wire up the functionality.

    Dude! .

  • Vince

    here’s a code correction or possibly just a suggestion. I had to use a different name for my NSURL. Though, at the same time I also put the URL inside the brackets in uppercase. That probably fixed it. Anyhow, the suggestion to icodeBlog and anyone else is to not use variable names that are too similar to Apple’s types. It’s generally frowned upon in other programming languages and usually impossible too. Xcode allows it because it is case sensitive.

    NSURL *destURL = [request URL];
    [iboTxtAddressBar setText:[destURL absoluteString]];

  • NCMacMan

    I’ve tried to implement autorotation within your code, but I can’t get it to work, do you know why? I set the autorotation to “return YES;” — no compile errors or SIGBRT encountered. Just no response in either the simulator or my hardware.

    Any help would be appreciated.

    Thanks…

  • apostleofzion

    Hi buddy,

    Thanks for the tutorial. :)
    Learned about the ‘WebView’ better.

  • apmobile

    Good Post, the only thing is that my GO BACK and FORWARD buttons doesn’t work.
    Ay idea.

  • Pingback: iPhone: Xcode

  • Jonathan Ness

    Someone asked earlier how to clear the webview between requests. Here’s how I did it:

    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]];

  • http://richardwillars.com Richard W

    Sussed out the orientation problem that people have been having.. when interface builder loads up double click on iCodeBlogViewController and build the browser in the view controller window that appears. Building it there instead of in the window seems to work..

  • Pingback: Some Great Resources! | My First iPhone Application

  • mms

    Hi,

    Thanks for your tutorial, and now I have a question, how to display the correct address after pressing “back” or “forward” button?

  • MBFromSantaBarbara

    Thanks for the great tutorial. I’m sure you’re too busy to answer all of these questions so I thought that I’d post some answers that may not be as elegant as yours…

    - How to ensure that url starts with “http://”…
    At the top of the gotoAddress method, add this code:
    // make sure url starts with “http://”
    if (! [addressBar.text hasPrefix:@"http://"]) {
    [addressBar setText:[NSString stringWithFormat:@"http://%@", addressBar.text]];
    }

    - how to update the addressBar after clicking go forward or go back:
    Make your webViewDidFinishLoad method look like this:
    - (void)webViewDidFinishLoad:(UIWebView *)webView{
    [addressBar setText:self.webView.request.URL.absoluteString];
    [activityIndicator stopAnimating];

    }

  • Pingback: 100 Free Courses & Tutorials for Aspiring iPhone App Developers | c'est la vie

  • Pingback: 100 Free Courses & Tutorials for Aspiring iPhone App Developers | c'est la vie

  • off

    If your “webViewDidStartLoad” doesn’t work -
    try to add this

    webView.delegate = self;

  • http://low-key.biz Urban

    Great Tutorial, finally one that demon straights the activity indicator!

    I have one problem though, when using your project im not able to rotate the application..

    Ive tried Return YES;
    &
    (interfaceOrientation == UIInterfaceOrientationLandscapeRight)

    But still not luck, please help

  • http://low-key.biz Urban

    Thanks for not even attempting to contact me

  • http://www.webjam.com/gadiks Usdating

    Great done and keep posted. Looking forward to reading more from you.

  • Pingback: iPhone uygulamaları geliÅŸtirmek isteyenler için ücretsiz 100 kurs ve rehber « Kerem PALABIYIK

  • Modder

    Hello

    The compiler says “Nested functions are disabled, use -fnested-functions to re-enable” at lines

    - (void)viewDidLoad {
    [super viewDidLoad];
    NSString *urlAddress @”http://google.com”;

    NSURL *url = [NSURL URLWithString:urlAddress];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

    [webView loadRequest:requestObj];
    [addressBar setText: urlAddress];
    }

    Any help appreciated!

    Regards,
    modder

    • http://headsfirst.nl Jr

      This error usually means you made a typo. In this case:
      you forgot a ‘=’ right in front of ‘@”http://google.com”‘.

      Cheers,
      Jr

      • kartik

        hey,
        can u tell how to open 192.168.1.1

  • brian olah

    great tutorial. I’m a noob and have gotten some pretty good results but…

    has anyone run across this in version 3.2.2:

    when i implement the viewDidLoad code to have a startup page, the app launches then immediately shuts down (ipad version).

    anyone with any thougths?

  • pankaj

    can u please tell me how did u implemented that white light when user taps on Address.

  • Malin

    All I want is a simple example of loading a web page via the web view control…no address bars, no buttons…just load a page when app is launched. I’m getting really frustrated with using Xcode…using Visual Studio is very straight forward…add a component, click on it, write your code…this jumping through hooping is really frustrating…create a wheel and put it over here…now put a button on the form, jump three times, recite Hamlet and bury the dog bone in the backyard….etc.

    Any help is greatly appreciated.

    Thanks,
    Malin

  • Pingback: House of the Magus

  • aaron parr

    Thanks for posting this tutorial. I was looking for exactly what you posted here.

  • Kimki

    Thanks!
    It operates correctly.
    But I need to get a content of specific address in html format.
    What do i do? Please help me.

  • Bess

    I run 3.1.3 and 3.2. Both version works. 3.2 call iPad simulator but everything works the same. Of course the UIWebView is showing iPhone size and UIWebView didn’t scratch out or size up to fit iPad screen 1024×768.

    I do encounter this warning. I couldn’t figure out how to remove this warning. I suspect it is related to how objects are connected in Interface Builder.

    /Users/XXX/ApplicationIphone/browser/MainWindow.xib:10:0 ‘Browser View Controller’ has both its ‘NIB Name’ property set and its ‘view’ outlet connected. This configuration is not supported.

  • Pingback: How to create Web Browser in iPhone SDK

  • http://www.yelacms.de Rene Pardon

    In my case webViewDidStartLoad and webViewDidFinishLoad are never called.

    I’ve created: Files Owner, First Responder, View (Navigation Bar (Navigation Item – title (btnWebBack, btnWebForward)), webView), MyViewController.

    They are linked as shown below:
    MyViewController: view – View, webView – webView
    webView: delegate – Files Owner, goBack – btnWebBack, goForward – btnWebForward, webView – MyViewController
    View: view – Files Owner/MyViewController
    Files Owner: view – View, delegate – webView

    My interface looks like:

    @interface MyViewController : UIViewController
    {

    }

  • http://www.yelacms.de Rene Pardon

    In my case webViewDidStartLoad and webViewDidFinishLoad are never called.

    I’ve created: Files Owner, First Responder, View (Navigation Bar (Navigation Item – title (btnWebBack, btnWebForward)), webView), MyViewController.

    They are linked as shown below:
    MyViewController: view – View, webView – webView
    webView: delegate – Files Owner, goBack – btnWebBack, goForward – btnWebForward, webView – MyViewController
    View: view – Files Owner/MyViewController
    Files Owner: view – View, delegate – webView

    My interface looks like:

    @interface MyViewController : UIViewController
    {
    IBOutlet UIWebView *webView
    }

    @property (nonatomic, retain) IBOutlet UIWebView *webView;

    -(IBAction)goForward:(id)sender;
    -(IBAction)goBack:(id)sender;
    @end

    I synthesize the webView in my implementation file and include the methods webViewDidStartLoad and webViewDidFinishLoad but neither the first nor the second one is called. I’ve tested with NSLog()

    • http://jexcy.com Cheng Yang

      I think you need to set webview’s delegate to file owner

  • http://www.coverboy.co.kr Mr.Black

    Awesome. Great thanks!!

  • chandra

    thanks,it easy to understand for new iphone developer. thanks again

  • http://pixel-shock.com cvb

    I have a webview as part of a tabbed application. The web view loads the page but the webViewDidFinishLoad never fires and the activityIndicatorView never goes away.

    I have it set up like the tutorial but I can’t seem to make the activityIndicatorView work. Any help is greatly appreciated.

    Thanks for the great tutorial.

  • Naruhodo

    Hello,

    I have inserted an Info View into tab bar, and I want a formatted text there so I placed UIWebView outlet in it.

    // InfoController.h

    #import
    @interface InfoController : UIViewController {
    IBOutlet UIWebView *webView;
    }
    @property (nonatomic, retain) IBOutlet UIWebView *webView;
    @end

    // InfoController.h

    @implementation InfoController
    @synthesize webView;
    - (void)viewDidLoad {
    [super viewDidLoad];
    NSString *infoFilePath;
    NSURLRequest *request;
    infoFilePath = [[NSBundle mainBundle] pathForResource:@”Info” ofType:@”html”];
    request = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:infoFilePath]];
    [self.webView loadRequest:request];
    }
    - (void)viewDidUnload {
    [super viewDidUnload];
    self.webView = nil;
    }
    - (void)dealloc {
    [webView release];
    [super dealloc];
    }
    @end

    It works fine.

    I would like to force mobilSafari to open if I click on one link in the UIWebView.
    So I placed web view delegate in the header file:
    @interface InfooController : UIViewController {
    and the
    - (BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
    [[UIApplication sharedApplication] openURL:[inRequest URL]];
    return NO;
    }
    code to the implementation file.
    If I connect webView delegate to the File’s Owner (InfoController) in IB then Info.html is not showed rather a white page only.
    What I’m doing wrong?

  • Amit Singh

    Nice Tutorial…….It sounds good for UIWebview’s…. I am having one issue except links if I want to detect some text from html data(javascript),Then added an event through javascript for selection and showing alert but I want to store that text in other variable for application side.. Then I want to perform rest of the actions through the app….Can u please tell me how can I Proceed…

    Thanks in advance….waiting for your reply…

  • Jesper

    I have changed a few things in the code, and not using the adressbar and back and forwardbuttons, and i get like 6 errors, to start with at;

    -(IBAction)gotoAddress;: (id) sender {
    NSURL *url = [NSURL URLWithString:[webView]];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

    [webView loadRequest:requestObj];

    it says ‘gotoAddress’ undeclared
    and Expected expression before ‘:’ token

    what to do?

  • Allison

    I was so excited when I found this (I just bought my mac 2 days ago, so this is all so new ot me)!
    I decided to try this tutorial, but nothing loads. I just get a black screen. I don’t get an errors when I build it. I have no idea how to run the debugger :)
    I saw the comments about adding the webView and view for the Referencing Outlets of the UIWebView window, so I made that change (so instead of a grey screen, I get a black screen). Any thoughts? Would it be because of SDK 4.2? Any help would be greatly appreciated! Thanks!

  • Jan

    i followed the tutorial, but under ios 4.2 .named the app ibrowser instead

    i get 2 Warnings about:

    – (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
    //CAPTURE USER LINK-CLICK.
    if (navigationType == UIWebViewNavigationTypeLinkClicked) {
    NSURL *URL = [request URL];
    if ([[URL scheme] isEqualToString:@”http”]) {
    [addressbar setText:[URL absoluteString]];
    [self gotoAddress:nil]; // here is the warning //warning:’ibrowserViewController’ may not respond to ‘-gotoAddress:’

    }
    return NO;
    }
    return YES;
    }

    and my app stays empty :( what did i made wrong? or is it handeled different in ios 4.2

  • Denis

    Thank you! That was very helpful to me to understand delegation!

  • http://www.ifixyouri.com cracked iphone

    Well, Of course the UIWebView is showing iPhone size and UIWebView didn’t scratch out or size up to fit iPad screen 1024×768.

  • Jon

    Brilliant, you’ve laid it all out very clearly and helped this iOS newb to get his navigation-based browsery first app working nicely. Thanks!

    Now, to simulate some accelerometer outputs why I consider shelling out on an actual living breathing iPhone..

    Jon.

  • Pingback: 100 cursos gratuitos y tutoriales para aspirantes a desarrolladores de App para iphone « Programacion « VENDO MI APPLE

  • paul morris

    I have followed this through to the word, my program builds and runs without errors or warnings but when it runs on the simulator i just got a black black screen,

    I have the icon in the home screen of simulator with my app name but just a blank screen.

    Any help?

  • http://twitter.com/EwanJL Ewan Leaver

    The video for creating the interface is no longer functioning due to the site no longer using wordpress. (Incorrect URL)

  • Elliotrock

    why is your code an image?

  • http://www.okmulgeeattorney.com Okmulgee Lawyer

    Nice post, thanx for the share.

    • Liljana Pendovska

      There are lot of hidden infos and those are basically in the Video. Could you please post the video as well. I am a newbie in iOS Apps and i still trying to get into the concept of iPhone apps with web.

      Thanks for the great tutorial tough.
      Lily :)

  • http://www.ladiesofhack.com ladiesofhack.com

    Awesome, Great work, Will be back soon:) Keep posting.

  • Tradomsk

    Can you send the link for the video? Thanks.

  • remi

    Thanks for this tutorial, this is exactly what I was looking for ;)

    Is it possible you upload the video concerning the User Interface Creation ? My activity indicator doesn’t work, I’m pretty sure I’m missing something in that part. All the other functionnalities are working, awesome !

  • mediation

    please send the link for the video? Thanks

  • Johan471

    many thanks, works like a charm. great tutorial :)

  • mediation

    Is it possible you upload the video concerning the User Interface Creation

  • olivier bornet

    Thanks ! 
    Someone know how to load in the webView a “HTTPS” (self signed) url ?

    I always have blank screen but on safari its work :/ 

  • electronfusion

    This entire article has been written in such a way that it relies on a video that is missing, and judging from previous comments, has been so for at least 2 months without any word back from the author. I’m a bit frustrated with this.

  • http://www.littleye.com internet blocking software

    Technology is so high tech nowadays as never before, even
    cell phone and iPhone are able to access internet nowadays like computers.
    Certainly, they are closer to PC; it also other kind of computer anyway. That’s
    how useful cell phones and iPhone to people nowadays, however there are also
    risk and danger with those device if you don’t know how to use it properly and
    mostly for kids. Internet had so many purposes, you can download videos,
    pictures and other stuff that you want to download or upload through computer
    and through it also you can download those things to your phone and iPhone
    including violence and pornography, that’s my point we don’t know if our kids
    are doing those stuffs with their phones and iPhone so it’s important to have a
    protection.

  • Sharanu Hugar007

    hey where is the video i am getting stuck with interface builder connection…

  • Nishant

    awesome tutorial…….Thanks a ton brandontreb

  • http://www.facebook.com/people/Rana-Yasir/100002577030597 Rana Yasir

    Well, I really enjoy this site and this is so good…………..Thanks

  • Michele Croci

    nice tutorial… but not so usefull without the video!

  • RM

    anyone managed to get the video ?

  • Fred

    Do you have a tutorial on how to do this with tabs, so that I can have more than one web view in the application?

  • Fhsjaagshs

    @b859bb4cec1c9bafc04fd3499814c15b:disqus  so people like you cannot copy it.
    and also, the delegate for the web view was never set to self. Fail.

  • Nguyenmphong

    i like this tutorial, thank much

  • Pbgeagon

    Please post video.

  • Polina Bhargavi

    hey how to expose java script functions and cal back to i phone app

  • Salim Fayad

    Is it possible to make the browser load websites that contain flash?

  • Bfoust1994

    Can you make a video plzzzz

  • http://www.yoekfashion.de/ mode für mollige

    There are so many users of iPhone.I must say that iPhone has influenced so much the life of the people. iPhone is one of the most used device in the world. 

  • Manish Sharma

    How can we implement download the  links appears on webpage..

  • Mncfhbzp
  • JimmyO

    Amazing that this was done 4-5 years ago and it is still the best step-by-step tutorial that I could find on setting up a UIWebView using Xcode.  A couple of things to note:
    1. the video is no longer available here, but there is a link the comments below that show the wayback machine location of where to find it.
    2. in the video itself, the voiceover does not match what is actually done on the screen when it comes to setting the delegate of the UIWebView.  I did what was done on the screen (it actually sets two delegates) and this results in a runtime error.  So instead do the following two things:
    a. do what is said verbally and only set one delegate for UIWebView to the webView.
    b. in the code in viewcontroller.m, add the following  inside the ViewDidLoad routine:
    webView.delegate = self;
    The above 2 steps will ensure that the webViewDidStartLoad and the webViewDidFinishLoad routines actually run.  Without doing 2b above everything compiles and works, but the activityIndicator does not run because these two routines do not run.

  • stephen

    dude dats one great tutorial..i m so greatful learned about webview….could u post tutorials on…. pulling content from website ….i mean the text ….anyways thanks

canakkale canakkale canakkale balik tutma search canakkale vergi mevzuati bagimsiz denetim vergi mevzuati ozurlu engelliler