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>
感謝您的幫助。
你能從文件中看到樣本內容嗎? – 2011-06-03 02:15:53
謝謝,我更新了帖子。 – funnyCoder 2011-06-03 02:20:25