Solved

How do I load a webpage using UIWebView ??

Posted on 2010-08-16
1
1,007 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Article by: Ph0en1x3
Abstract - With Apple producing millions of units annually, it might make good business sense to become an Apple Certified Development center. The iPhone, iPad, and iPod consistently use the same SDK and development methodologies and this process al…
Short answer to this question: there is no effective WiFi manager in iOS devices as seen in Windows WiFi or Macbook OSx WiFi management, but this article will try and provide some amicable solutions to better suite your needs.
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…

809 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