如何加载顶部有关闭按钮的 UIWebView?
我目前有以下代码从另一个视图加载 UIWebView。现在我可以有一个关闭按钮吗?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIWebView *webView=[[UIWebView alloc] initWithFrame:CGRectMake(0,0,320,480)];
[self.view addSubview:webView];
NSURLRequest *urlRequest;
NSURL *urlforWebView;
urlforWebView=[NSURL URLWithString:@"http://www.google.com"];
urlRequest=[NSURLRequest requestWithURL:urlforWebView];
[webView loadRequest:urlRequest];
}
我将加载一个使用 jquery mobile 构建的页面,因此页面内的关闭按钮也可以正常工作。但在导航栏上会是理想的选择。顺便说一句,我的应用程序没有有 UINavigationBar
I currently have the following code that loads a UIWebView from another View. Now is there anyway I can have a close button?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIWebView *webView=[[UIWebView alloc] initWithFrame:CGRectMake(0,0,320,480)];
[self.view addSubview:webView];
NSURLRequest *urlRequest;
NSURL *urlforWebView;
urlforWebView=[NSURL URLWithString:@"http://www.google.com"];
urlRequest=[NSURLRequest requestWithURL:urlforWebView];
[webView loadRequest:urlRequest];
}
I am going to load a page built using jquery mobile, so a close button inside the page would also work fine. But on a navigation bar would be ideal. Btw, my application does not have a UINavigationBar
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我将创建一个新的
UIViewController
子类,例如带有笔尖的WebViewController
。然后我将添加一个带有关闭按钮的 UINavigationBar 和一个 UIWebView。然后,要显示您的 Web 视图控制器,您可以执行以下操作:在您的
WebViewController
中,您可以定义:并实现如下所示的操作:
I would create a new sub class of
UIViewController
, sayWebViewController
with a nib. Then I would add anUINavigationBar
with a close button and anUIWebView
. Then to show your web view controller you can do something like:In your
WebViewController
you can define:and implement something like this:
每当加载 UIWebView 时,您都可以先在内容上运行 javascript 片段。
这只是劫持了 window.close() 的正常行为,让您有机会在 Objective-C 中捕获该调用。
然后在你的 UIWebViewDelegate 中你可以监听你选择作为关闭 url 的任何内容。
有点 hackish,但它允许 Web 开发人员从 HTML 内容中控制关闭按钮的外观和感觉。
Whenever you load the UIWebView, you could run a javascript snippet on the content first.
That just hijacks the normal behavior of
window.close()
and gives you chance to catch the call in your Objective-C.Then in your UIWebViewDelegate you could listen for whatever you chose as the close url.
A bit hackish, but it would allow the web developer to control the look and feel of the close button from within the HTML content.