添加一个“关闭”按钮Three20 TTWebController - iPhone
我使用这个代码呈现TTWebController为模态的视图:添加一个“关闭”按钮Three20 TTWebController - iPhone
TTNavigator* navigator = [TTNavigator navigator];
TTURLMap* map = navigator.URLMap;
[map from:@"*" toModalViewController:[TTWebController class]];
一切都很正常,只是没有对TTWebController没有“关闭”按钮。我知道这通常是从旁边推,并给出一个“后退”按钮,但有没有办法添加一个“关闭”按钮,而不挖掘到实际的Three20代码?
更新:
这里是我使用创建文本,然后按下模态查看到屏幕上的代码。我想动态地发送任何一个URL被点击,而不是“YourUrlHere”。
CGRect frame = CGRectMake(100, 100, 200, 200);
TTStyledTextLabel* label = [[[TTStyledTextLabel alloc] initWithFrame:frame] autorelease];
NSString* labelText = @"http://www.yahoo.com http://www.google.com http://www.test.com";
label.text = [TTStyledText textFromXHTML:labelText lineBreaks:NO URLs:YES];
[self.view addSubview:label];
TTNavigator* navigator = [TTNavigator navigator];
TTURLMap* map = navigator.URLMap;
myWebView *newViewController = [[myWebView alloc] initWithNibName:@"TTStyledTextLabelWebView" bundle:nil incomingURL:[NSString stringWithString:@"http://www.YourUrlHere.com"]];
[map from:@"*" toModalViewController:[newViewController class]];
也许你真正想要的是你自己的视图控制器,它可以是继承自或包含TTWebController。创建并映射到那个,而不是原始的TTWebController
,把按钮放在任何你喜欢的地方,然后把它连接到[self dismissModalViewControllerAnimated:YES];
这应该会有效。
编辑:
所以,现在你有myWebView
类型,我从TTWebController
假设继承的自定义Web视图。那很好。顺便说一下,你并不需要初始化它的一个新实例来获得该类,只需要即可,因为类消息位于类上,而不是实例。
但是,即使您已决定使用xib创建新实例,但我不认为TTNavigator将以同样的方式实例化您的控制器实例。相反,我相信它会与此构造(从TTWebController.m提取)
- (id)initWithNavigatorURL:(NSURL*)URL query:(NSDictionary*)query {
if (self = [self init]) {
NSURLRequest* request = [query objectForKey:@"request"];
if (request) {
[self openRequest:request];
} else {
[self openURL:URL];
}
}
return self;
}
所以推出,在你的孩子实现,可以提供这个实现的定制版本,像这样:
- (id)initWithNavigatorURL:(NSURL*)URL query:(NSDictionary*)query {
if (self = [super initWithNavigatorURL:URL query:query]) {
// code that creates a button and puts it somewhere
}
return self;
}
我没有测试过它,如果它没有这样做,我会有兴趣看看它实际上在做什么。如果你喜欢xibs(像我一样,不像three20),那么你需要做一个额外的加载步骤。我在我的工具框架的类别,与这有助于:
一个NSBundle + LoadNibView.h
#import <Foundation/Foundation.h>
@interface NSBundle(LoadNibView)
+ (id) loadNibView:(NSString*)className;
@end
一个NSBundle + LoadNibView.m
#import "NSBundle+LoadNibView.h"
@implementation NSBundle(LoadNibView)
+ (id) loadNibView:(NSString*)className
{
return [[[NSBundle mainBundle] loadNibNamed:className owner:nil options:nil] objectAtIndex:0];
}
@end
的objectAtIndex
部分是因为所有xib都包含一个数组,即使里面只有一个视图。这将只返回xib中的第一个UIView。
该映射看起来不正确,你真的想用*吗? – slf 2011-01-06 16:08:19
是的......链接工作并打开模态视图。问题是TTWebController没有“关闭”按钮。 – Chris 2011-01-06 16:12:14