Solved

How do I load a webpage using UIWebView ??

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Upgrade iphone 6s plus from 9.3.2 to 9.3.3 5 87
Iphone 4S gone suddenly dead 6 63
iPhone 6: Testing my battery for failure? 6 61
Backup / Restore an iphone 8 69
The release of the iPhone 6 and iPhone 6 Plus was a complete game changer for Apple. Steve Jobs had even showed his distaste for larger phones, calling them “Hummers”. But to compete with larger smartphones, Apple finally introduced the iPhone 6 wit…
Let Bitmoji into your life. Now is the time to learn a new language of smartphone messaging with this brief introduction.
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…

911 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

24 Experts available now in Live!

Get 1:1 Help Now