添加一个“关闭”按钮Three20 TTWebController - iPhone
-
26-09-2019 - |
题
我使用此代码呈现TTWebController作为模态的视图:
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
的自定义Web视图,我假设从TTWebController
继承。非常好。顺便说一句,你不是真的需要初始化它的一个新实例只是为了获取类,你可以做到这一点,只需[myWebView class]
因为该类消息的类,而不是实例。
然而,即使您已决定创建使用厦门国际银行的新实例,我不认为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
部分是因为所有xibs包含一个数组,即使只有一个视图内。这将只返回第一的UIView在XIB。