单击另一个 Web 视图上的图像后在 Web 视图中打开图像?
我正在开发一个 iPhone 应用程序,其中有大表格可以在网络视图上显示。我计划在实际表格的位置提供一个小图像,当用户单击它时,实际图像将在另一个 webView 中打开。我正在寻找正确的方向。请帮忙。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为包含小图像的第一个 Web 视图实现 UIWebViewDelegate 协议方法
shouldStartLoadWithRequest
。当用户单击您的图像时,您需要拦截此事件并决定做什么以及如何做。
shouldStartLoadWithRequest 方法。请参阅 UIWebView 文档 了解更多详细信息。 shouldStartLoadWithRequest 必须返回一个 BOOL 来指示 webview 应该继续执行用户执行的操作(返回 YES)或不继续(返回 NO)。
现在您知道已单击链接,您必须确保它是图像。这是通过评估请求参数传回的 url 来完成的。我在示例中编写了一个方法 clickedOnImageWithUrl ,如果单击图像,该方法将返回 YES 。但是,我不知道链接中嵌入的小图像是什么样子,我无法提供有关该方法的更多详细信息。如果返回 YES,您可以显示新的 webView。
然后,代码可能如下所示以拦截单击的链接:
Implement the UIWebViewDelegate protocol method
shouldStartLoadWithRequest
for your first webview containing your small images.When a user clicks your image you need to intercept this event and decide what and how to do.
The shouldStartLoadWithRequest method is called when some kind of interaction is triggered in you webview, such as a link being clicked. Refer to the UIWebView documentation for more detail. The shouldStartLoadWithRequest has to return a BOOL to indicate the webview that it should proceed with the action the user performed(return YES) or not(return NO).
Now that you know that a link has been clicked you have to make sure, that it has been an image. This is done by evaluate the url passed back by the request parameter. I've made up a method clickedOnImageWithUrl in the example, which will return YES if an image has been clicked. However, I don't know what your small images embedded in a link look like I cannot provide any more detail on that method. If it returns YES you can show your new webView.
Then the code could look like this to intercept a clicked link:
@Yogi:当你要在另一个 webView 中显示图像时,为什么要在 UIWebView 之上有一个表格视图。我想只有一个 WebView 就足够了。顺便说一句,您可以通过拥有图像详细信息的字典或者甚至包含图像 url 的数组来实现您想要的功能。在UITableViewDelegate方法中,
您可以使用indexpath将图像的url传递给webview,webview可以打开url来查看图像。
@Yogi: Why do you want to have a table view on top of a UIWebView when you are going to display the image in another webView. I guess just one WebView would be sufficient. By the way you can implement what you want by having a dictionary for the details of the image or perhaps even an array which contains the url for the images. And in the UITableViewDelegate method
You can pass the url of the image using the indexpath to the webview which can open the url to view the image.