在我的應用程序(故事板)的一部分中我有一個表視圖與各種行,當我選擇一行時,應顯示一個html文件。相反,當我選擇一行時,我得到一個空白屏幕。在表中選擇一行時,它會切換到空白屏幕
我以爲我需要tableview控制器後的另一個視圖控制器,但我得到同樣的問題,無論我有沒有。
在我的表控制器.m文件我有以下代碼:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
articleIndex = indexPath.row;
WebView *selectedArticle = [[WebView alloc] initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:selectedArticle animated:YES];
[selectedArticle release];
那就是讓我來選擇行和屏幕變爲空白的一個,而比加載相關的html文件。
我有我的資源文件夾中的h和.m文件如下:
webView.h
#import <UIKit/UIKit.h>
#import "globals.h"
@interface WebView : UIViewController{
NSArray *articleNames;
IBOutlet UIWebView *webView;
}
@property(nonatomic, retain)IBOutlet UIWebView *webView;
@end
webView.m
#import "WebView.h"
@implementation WebView
@synthesize webView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
articleNames = [[NSArray arrayWithObjects:
@"chapter1",
@"chapter2",
@"chapter3",
@"chapter4",
@"chapter5",
@"chapter6",
nil] retain];
NSString *chapterName = [[NSString alloc] initWithString:[articleNames objectAtIndex:articleIndex]];
NSString *path = [[NSBundle mainBundle] pathForResource:chapterName ofType:@"html"];
NSURL *url = [NSURL fileURLWithPath:path];
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url];
[webView loadRequest:urlRequest];
[chapterName release];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
@end
我什麼也看不見我在這裏做錯了,有什麼建議嗎?我不知道如何讓html文件顯示,或者我需要進行更改以允許它。如果我從項目中刪除的HTML文件應用程序崩潰,所以它肯定是加載它們,但由於某種原因不顯示...