将UIWebView推入UIViewController
几乎所有我看到的例子都是使用IB完成的,但我不想使用IB。
我想要做的是,当用户在表格中选择一行时,UIWebView将被压入堆栈并加载该特定页面,同时保持标签栏和导航栏。 我不希望浏览器的所有功能只能够滚动页面,因为我的应用程序的其余部分控制着一个人如何通过表格浏览网站。
所以我已经能够推动其他viewcontrollers,但用相同的方法推UIWebView不起作用。
这是我到目前为止..
这是Threads.h文件
#import "ThreadContent.h"
#import <UIKit/UIKit.h>
@interface Threads : UITableViewController {
NSMutableArray *threadName;
NSMutableArray *threadTitle; 
UIActivityIndicatorView *spinner;
NSOperationQueue *operationQueue;
UILabel *loadingLabel;
NSMutableDictionary *cachedForum;
NSMutableArray *forumID;
NSInteger *indexPathRowNumber;
NSMutableArray *threadID;
ThreadContent *threadContent;
}
@property (nonatomic, assign) NSMutableArray *forumID;
@property (nonatomic, assign) NSInteger *indexPathRowNumber;
@end
我正在尝试推送UIWebView的Threads.m文件的一部分
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"%i",indexPath.row);//get row number
NSLog(@"%@", [threadID objectAtIndex:indexPath.row]);//thread id
                                                     //forums.whirlpool.net.au/forum-replies.cfm?t=
                                                     //NSString *urlString = [NSString stringWithFormat:@"forums.whirlpool.net.au/forum-replies.cfm?t=%@",  [threadID objectAtIndex:indexPath.row]];
threadContent = [[ThreadContent alloc] init];
[self.navigationController pushViewController:threadContent animated:YES];
}
我的WebView文件..以及我不知道如何做到这一点? 我确实把它做成了一个“UIWebView”子类,但是如果我尝试将它推到堆栈上,我得到一个崩溃,说它需要它成为“UIViewController”子类。
  UIWebView是UIView而不是UIViewController的子类。 
您需要继承UIViewController(将其称为WebViewController)
  在viewDidLoad方法中,使用addSubview:创建一个UIWebView并将其添加到视图中addSubview:您可以传递该URL以作为WebViewController的属性加载到webView中 
-(void)viewDidLoad {
    UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
    [self.view addSubView:webView];
    [webView loadRequest:[NSURLRequest requestWithURL:self.urlToLoad]];
    [webView release];
}
  和Threads 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"%i",indexPath.row);//get row number
    NSLog(@"%@", [threadID objectAtIndex:indexPath.row]);//thread id
                                                     //forums.whirlpool.net.au/forum-replies.cfm?t=
                                                     //NSString *urlString = [NSString stringWithFormat:@"forums.whirlpool.net.au/forum-replies.cfm?t=%@",  [threadID objectAtIndex:indexPath.row]];
    threadContent = [[ThreadContent alloc] init];
    threadContent.urlToLoad = [NSURL URLWithString:urlString];
    [self.navigationController pushViewController:threadContent animated:YES];
}
  (或者使webView成为一个属性,并在您将Threads的WebViewController推入之前或之后调用load方法,但我不能100%确定这种方式是否可行) 
