2

当我在某个链接上时,如何更改UIWebView tap操作 Controls.like ..它会打开一个带有三个选项的...我需要更改此控件,例如 ..我需要再添加一个按钮...如何做那...如何禁用它并根据我的选择添加新的...tap and holdUIWebViewUIActionSheetopen copy add to reading listUIActionsheetUIActionSheet

在此处输入图像描述

代码

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *requestURL = [ request URL];

if (navigationType == UIWebViewNavigationTypeLinkClicked)
{
    // Call your custom actionsheet and use the requestURL to do what you want :)


    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Contextual Menu"
                                                       delegate:self cancelButtonTitle:@"Cancel"
                                         destructiveButtonTitle:nil otherButtonTitles:nil];

    [sheet addButtonWithTitle:@"Save Page as Bookmark"];
    [sheet addButtonWithTitle:@"Open Page in Safari"];

    [sheet showInView:webView];
    return NO;
}

return YES;
}


- (void)viewDidLoad
{
[super viewDidLoad];

[webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://google.com"]]];

webview.delegate=self;

}



- (void)actionSheet:(UIActionSheet *)actionSheet
clickedButtonAtIndex:(NSInteger)buttonIndex {


if (buttonIndex == actionSheet.cancelButtonIndex) { return; }
switch (buttonIndex) {
    case 0:
    {
        NSLog(@"Item A Selected");
   NSLog(@"reg%@", request);

          NSURL *requestURL = [request URL];
        [webview loadRequest:[NSURLRequest requestWithURL:requestURL]];



        break;
    }
    case 1:
    {
        NSLog(@"Item B Selected");


        break;
    }

}

}

4

1 回答 1

1

你可以这样做,点击链接然后使用你的操作表

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType 
{
    NSURL *requestURL = [ request URL];

    if (navigationType == UIWebViewNavigationTypeLinkClicked)
    {
        // Call your custom actionsheet and use the requestURL to do what you want :)
        return NO;
    }

    return YES;
}


- (void)viewDidLoad
{
    [super viewDidLoad];


     webview.delegate=self;
     [webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://google.com"]]];



}
于 2013-01-29T07:15:57.453 回答