我试图从three20表控制器显示本地html文件。表格正确显示,但是当我选择该项目时,我所得到的只是一个空白屏幕。如果我使用外部URL,则页面显示正确。我还没有尝试过使用UIWebView,但我想知道是否有使用Three20框架的简单方法。Three20显示本地html文件
谢谢。
我试图从three20表控制器显示本地html文件。表格正确显示,但是当我选择该项目时,我所得到的只是一个空白屏幕。如果我使用外部URL,则页面显示正确。我还没有尝试过使用UIWebView,但我想知道是否有使用Three20框架的简单方法。Three20显示本地html文件
谢谢。
编辑:我忘了that has changed最近...
假设您已经注册了您的导航器TTWebController
这样:
TTNavigator* navigator = [TTNavigator navigator];
TTURLMap* map = navigator.URLMap;
[map from:@"*" toViewController:[TTWebController class]];
你可以简单地打开本地HTML文件的方式:
NSString *creditsPath = [[NSBundle mainBundle] pathForResource:@"credits" ofType:@"html"];
NSURL *url = [NSURL fileURLWithPath:creditsPath];
TTOpenURL([url description]);
然后,你只需要添加TTTableLinkedItem
或subcl驴(几乎所有的TT *小区内有)到你的数据源与本地文件URL这样的:
NSString *creditsPath = [[NSBundle mainBundle] pathForResource:@"credits" ofType:@"html"];
NSURL *url = [NSURL fileURLWithPath:creditsPath];
TTTableTextItem *item = [TTTableTextItem itemWithText:@"foobar" URL:[url description]];
简单多了什么我以前写...
ENDOFEDIT
忘记whats下,除非你有兴趣在别人的解决方案...(更复杂...或不,看最后一个)
基本上这里是你如何在UIWebView
OAD内容:
NSString *creditsPath = [[NSBundle mainBundle] pathForResource:@"credits" ofType:@"html"];
NSURL *url = [NSURL fileURLWithPath:creditsPath];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[webView loadRequest:urlRequest];
的three20
TTWebController
可以在查询请求:
- (id)initWithNavigatorURL:(NSURL*)URL query:(NSDictionary*)query {
if (self = [self initWithNibName:nil bundle:nil]) {
NSURLRequest* request = [query objectForKey:@"request"];
if (nil != request) {
[self openRequest:request];
} else {
[self openURL:URL];
}
}
return self;
}
所以要打开一个TTWebController
本地HTML文件,你可以这样做:
NSString *creditsPath = [[NSBundle mainBundle] pathForResource:@"credits" ofType:@"html"];
NSURL *url = [NSURL fileURLWithPath:creditsPath];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[[TTNavigator navigator] openURLAction:
[[[TTURLAction actionWithURLPath:@"url://to/your/ttwebcontroller"]
applyQuery:[NSDictionary dictionaryWithObject:ulrRequest
forKey:@"request"]]
applyAnimated:YES]];
现在最后一部分,从TTTableViewController
触发这个... 你有y我们的ViewController
实施:
- (void)didSelectObject:(id)object atIndexPath:(NSIndexPath*)indexPath {
// there you retrieve a *TTTableItem* corresponding to your row
// and call previous snippet from URL...
// TTTableItem class has userInfo property you could use:
TTTableItem *item = (TTTableItem *)object;
NSString *htmlFile = item.userInfo.
[self openLocalHtmlFile:htmlFile];
}
希望帮助! 没有测试过任何东西,不应该编译或任何,但这是一个解决方案。
这是一个使用基本的three20 + iOS功能的解决方案。你也可以写一个TTCustomWebController
从TTWebController
继承,将采取类似的网址是@"myapp://openLocalHtml?file=credits"
并不难做到...
...这里是一个草案:
@interface TTCustomWebController : TTWebController {}
@end
@implementation TTCustomWebController
- (id)initWithFile:(NSString *)name {
self = [super init];
if (self) {
NSString *filePath = [[NSBundle mainBundle] pathForResource:name ofType:@"html"];
NSURL *URL = [NSURL fileURLWithPath:filePath];
[self openURL:URL];
}
return self;
}
@end
然后,你可以简单地使用TTTableLinkedItem
在你的数据源中指向这些@"myapp://openLocalHtml?file=credits"
...
祝你好运!:)
非常感谢!我会让你知道它是怎么回事! – Andy 2011-06-06 14:03:45