2011-06-03 51 views
1

我想用UITableView创建一个应用程序,并选择一行进入另一个视图,该视图包含将加载某个网站(传入该行)的UIWebView。但我仍然得到这个日志:用UIWebView和UITableView导航应用程序

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

感谢您的帮助。

+0

你能从文件中看到样本内容吗? – 2011-06-03 02:15:53

+0

谢谢,我更新了帖子。 – funnyCoder 2011-06-03 02:20:25

回答

1

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

+0

哇,这是真棒男人:)谢谢。 – funnyCoder 2011-06-03 02:26:08