带有动作的文本字段无法在iPad上运行

时间:2012-08-15 04:29:43

标签: ios uibutton uitextfield

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

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

    locationField.leftView = bookMarkButton;

bookMarks方法

- (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];
        }
    }

}

1 个答案:

答案 0 :(得分: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];
 }
}