funnyCoder
funnyCoder

Reputation: 825

Navigation application with UIWebView and UITableView

I'm trying to create an application with a UITableView and when selection a row going to another view that containing a UIWebView that will load some website(passing in the row). but i still got this log :

Unknown scheme, doing nothing:

My code is below :

// RootViewController.h

#import <UIKit/UIKit.h>

@interface RootViewController : UITableViewController {
    NSArray *books;
    NSArray *sites;
    NSArray *contacts;
}

// RootViewController.m

#import "RootViewController.h"
#import "SitesViewController.h"

@implementation RootViewController

- (void)viewDidLoad
{
    // Setting the main screen title
    self.title = @"Main App Screen";

    // Retreiving data from the plist file
    NSString *file = [[NSBundle  mainBundle] pathForResource:@"Data"    ofType:@"plist"];

    NSDictionary    *dict = [[[NSDictionary   alloc] initWithContentsOfFile:file] autorelease];

    sites = [[NSArray    alloc] initWithArray:[dict    objectForKey:@"Sites"]];
    contacts = [[NSArray    alloc] initWithArray:[dict    objectForKey:@"Contacts"]];
    books = [[NSArray    alloc] initWithArray:[dict    objectForKey:@"Books"]];

    [super viewDidLoad];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // We have 3 sections
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Returning the number of rows

    return numberOfrows;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Returning each cell
    return cell;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    // section title
    return title;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Handling sites section
    if (indexPath.section == 0) {
        SitesViewController *sitesViewController = [[SitesViewController    alloc] initWithNibName:@"SitesViewController" bundle:nil];

        // We want to load some data here
        sitesViewController.websiteUrl = [sites objectAtIndex:indexPath.row];
        // Load this view
        [self.navigationController  pushViewController:sitesViewController animated:YES];
        // Release it
        [sitesViewController release];
    }
}

// SitesViewController.h

#import <UIKit/UIKit.h>


@interface SitesViewController : UIViewController {
    IBOutlet UIWebView  *website;
    NSString *websiteUrl;
}

@property (nonatomic, retain) IBOutlet UIWebView *website;
@property (nonatomic, retain) NSString *websiteUrl;

@end

// SitesViewController.m

#import "SitesViewController.h"


@implementation SitesViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    //[website    setDelegate:self];
    // Do any additional setup after loading the view from its nib.
    NSURL *url = [[NSURL alloc] initWithString:websiteUrl];
    [website    loadRequest:[NSURLRequest   requestWithURL:url]];
    [url release];
}

....

@end

As requested the Data.plist file contain this data :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Sites</key>
    <array>
        <string>www.freebsd.com</string>
        <string>www.kernel.org</string>
        <string>www.developer.apple.com</string>
        <string>www.github.com</string>
    </array>
    <key>Contacts</key>
    <array>
        <string>[email protected]</string>
        <string>[email protected]</string>
        <string>[email protected]</string>
    </array>
    <key>Books</key>
    <array>
        <string>book1</string>
        <string>book2</string>
        <string>book3</string>
    </array>
</dict>
</plist>

Thanks for the help.

Upvotes: 1

Views: 853

Answers (1)

Deepak Danduprolu
Deepak Danduprolu

Reputation: 44633

You will need to add http:// to those urls. They aren't automatically prepended with it.

Upvotes: 1

Related Questions