【问题标题】:Navigation application with UIWebView and UITableView带有 UIWebView 和 UITableView 的导航应用程序
【发布时间】:2011-06-03 02:09:00
【问题描述】:

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).但我仍然得到这个日志:

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>

感谢您的帮助。

【问题讨论】:

  • 您能否展示您文件中的示例内容?

标签: iphone uitableview uiwebview uinavigationcontroller


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2011-08-25
    • 2011-08-17
    • 1970-01-01
    • 1970-01-01
    • 2012-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-24
    相关资源
    最近更新 更多