Solved

How do I load a webpage using UIWebView ??

Posted on 2010-08-16
1
1,005 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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
location of pointed at object 4 76
itunes and ipod touch 2 60
iphone 6 18 47
OPINION - Going to write an App 3 45
There is a security feature on iOS devices that is nearly impenetrable when it has been activated.  This article will provide some possible solutions as well as necessary steps to take to ensure you do not end up with a locked device.
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now