我看到的几乎所有例子都是用IB完成的,但我不想使用IB.
我想要做的是,当用户选择表中的行时,UIWebView将被推入堆栈并加载该特定页面,同时保持标签栏和导航栏.我不希望浏览器的所有功能都只能滚动浏览页面,因为我的应用程序的其余部分控制着人们如何通过表格浏览网站.
所以我已经能够推送其他视图控制器,但使用相同的方法推送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
Run Code Online (Sandbox Code Playgroud)
我正在尝试推送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];
}
Run Code Online (Sandbox Code Playgroud)
我的WebView文件..好吧,我不知道该怎么做?我确实把它变成了一个"UIWebView"子类,但是如果我试着把它推到堆栈上,我会发现它需要它成为一个"UIViewController"子类.
UIWebView是非UIViewUIViewController 的子类.
你需要子类UIViewController(例如调用它作为WebViewController)
并在该viewDidLoad方法中创建一个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];
}
Run Code Online (Sandbox Code Playgroud)
并在 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];
}
Run Code Online (Sandbox Code Playgroud)
(或者在推入WebViewController之前或之后将webView作为属性并调用load方法Threads,我不是100%确定这种方式是否有效)