使用UIWebView和UITableView导航应用程序

时间:2011-06-03 02:09:00

标签: iphone uitableview uiwebview uinavigationcontroller

我正在尝试使用UITableView创建一个应用程序,当选择一行进入另一个包含UIWebView的视图时,该视图将加载一些网站(传入该行)。但我还有这个日志:

Unknown scheme, doing nothing:

我的代码如下:

// 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

根据要求,Data.plist文件包含以下数据:

<?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>user@apple.com</string>
        <string>user@kernel.org</string>
        <string>user@gmail.com</string>
    </array>
    <key>Books</key>
    <array>
        <string>book1</string>
        <string>book2</string>
        <string>book3</string>
    </array>
</dict>
</plist>

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

您需要将http://添加到这些网址中。它们不会自动添加它。