开发者

Opening an image in a web view on clicking an image on another web view?

I am developing an iPhone app in which there are big tables to show on web view. I am planning开发者_如何学Python to give a small image at the place of actual table and when the user will click on that, the actual image will open in another webView. I am looking for right direction. Please help.


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:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)aRequest navigationType:(UIWebViewNavigationType)navigationType
{
    if (navigationType == UIWebViewNavigationTypeLinkClicked) {
        // check if user clicked on your image...clickedOnImageWithUrl is made up
        if([self clickedOnImageWithUrl:[aRequest url]]) {

             // push new webview with image ...

             return NO;
        }            
    }

    return YES;
}


@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

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;

You can pass the url of the image using the indexpath to the webview which can open the url to view the image.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Get the url for the image here
NSUrlRequest *urlRequest = [NSUrlRequest requestWithURL:urImageUrl];
[urWebView loadRequest:urlRequest];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜