Solved

How do I load a webpage using UIWebView ??

Posted on 2010-08-16
1
1,008 Views
Last Modified: 2012-05-10
Hi,
I just want to have a simple application that loads up the website. This is the codes that i have on webcontroller.h and webcontroller.m. I'd attached the .xib in the snapshot photo.

webcontroller.h
--------------------

#import <UIKit/UIKit.h>


@interface WebViewController : UIViewController <UIWebViewDelegate> {
      
      //The 2nd outlet is created of type UIWebView so that everytime it is accessed,
      //you don't have to cast the UIView into a UIWebView like below:
      //(UIWebView*) [self view] or (UIWebView*) self.view
      IBOutlet UIWebView *webView;
}

@end


webcontroller.m
==============

#import "WebViewController.h"


@implementation WebViewController



 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        // Custom initialization
    }
    return self;
}



// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
      
      NSURL *url = [NSURL URLWithString:@"www.mywebsite.com"];
      
      NSURLRequest *theNSURLRequest = [NSURLRequest requestWithURL:url];
      
      [(UIWebView*) self loadRequest:theNSURLRequest];
      
}


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
   
    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end


Can anyone help me? With the codes/setting above, I'm not getting anything when it loads.

Thanks.
WebViewController.tiff
0
Comment
Question by:tangteng78
1 Comment
 
LVL 33

Accepted Solution

by:
pgnatyuk earned 500 total points
ID: 33451723
It is short and simple:
UIWebView Tutorial
http://www.iphonesdkarticles.com/2008/08/uiwebview-tutorial.html

iPhone Coding – Learning About UIWebViews by Creating a Web Browser
http://icodeblog.com/2008/12/19/iphone-coding-learning-about-uiwebviews-by-creating-a-web-browser/

iPhone UIWebView tutorial
http://www.gibsontang.com/?p=176

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    
  
    CGRect webFrame = CGRectMake(0.0, 0.0, 320.0, 460.0);
    UIWebView *webView = [[UIWebView alloc] initWithFrame:webFrame];
    [webView setBackgroundColor:[UIColor whiteColor]];
    NSString *urlAddress = @"http://www.google.com";
    NSURL *url = [NSURL URLWithString:urlAddress];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [webView loadRequest:requestObj];
    [window addSubview:webView]; 
    [webView release];  
    [window makeKeyAndVisible];
        
    return YES;
}

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

iCloud Drive was introduced after iOS 8 was launched last year. This drive is Apple’s online storage device that lets users sync their files and access them from all their Apple devices.   There is a lot of data that is not automatically backed up…
Is your phone running out of space to hold pictures?  This article will show you quick tips on how to solve this problem.
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question