0

我在我的文本字段中创建了一个按钮并调用我的bookMarks方法。这适用于iphone。如果我在工具栏中创建一个按钮并调用此方法,仍然可以正常工作。它只是在我的文本字段中不起作用。有没有办法解决这个问题?谢谢..

 [bookMarkButton addTarget:self action:@selector(bookMarks:) forControlEvents:UIControlEventTouchUpInside];

    locationField.leftView = bookMarkButton;

书签法

- (void)bookMarks:(id)button {

    if (self.bookmarkPopoverController.popoverVisible) {
        [self.bookmarkPopoverController dismissPopoverAnimated:YES];
        self.bookmarkPopoverController = nil;
    } else {
        ViewBookmarkViewController * viewBookmarkViewController = [[[ViewBookmarkViewController alloc] initWithStyle:UITableViewStyleGrouped] autorelease];
        viewBookmarkViewController.delegate = self;
        [viewBookmarkViewController setBookmark:[webView stringByEvaluatingJavaScriptFromString:@"document.title"]
                                        url:self.url];
        UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:viewBookmarkViewController] autorelease];

        navController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
            self.bookmarkPopoverController = [[[UIPopoverController alloc] initWithContentViewController:navController] autorelease];
            [self.bookmarkPopoverController presentPopoverFromBarButtonItem:button
                                                   permittedArrowDirections:UIPopoverArrowDirectionDown|UIPopoverArrowDirectionUp
                                                                   animated:YES];
        } else {
            [self presentModalViewController:navController animated:YES];
        }
    }

}
4

1 回答 1

0

为什么不为 textField 添加 ControlEvent:

[yourTextField addTarget:self action:@selector(bookMarks:) forControlEvents:UIControlEventTouchUpInside];

编辑:要区分按钮,分别将标签 0 和 1 添加到两个按钮;

现在你的方法是:

- (void)bookMarks:(id)sender 
{ 
  if([sender isKindOfClass:[UIButton class]]) 
  {
   UIButton *curBtn = (UIButton *)sender
   if([curBtn tag] == 0)
   {
     // any action for button 1
   }
   else if([curBtn tag] == 1)
   {
      //refresh uiWebView
   }
  }
 else
 {
   //your code
   //present your popover for ipad
   [[self.bookmarkPopoverController presentPopoverFromRect:yourtextFeild.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown|UIPopoverArrowDirectionUp animated:YES];
 }
}
于 2012-08-15T04:54:40.280 回答