1

我想了解如何让 UITextField 从 UIPopover 视图中获取文本。假设我的弹出框上有带有数字的按钮,我希望将这些数字输入到文本字段中。

有些人向我们建议 BOOL 是这样的:

- (BOOL)textFieldShouldBeginEditing:(UITextField *) textField {
  [self.myPopover presentPopoverFromRect:textField.frame 
        inView:self.view 
        permittedArrowDirections:UIPopoverArrowDirectionAny
        animated:YES];
  return NO;
} 

还有一个:

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView {
  if(popoverController == nil){   //make sure popover isn't displayed more than once in the view
    popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverDetailContent]; 
  }
  [popoverController presentPopoverFromRect:textView.frame 
        inView:self.view 
        permittedArrowDirections:UIPopoverArrowDirectionAny
        animated:YES];
  popoverController.delegate = self;
  return NO; // tells the textfield not to start its own editing process (ie show the keyboard)
}

两者都没有太大变化,我的 textField 仍然调用默认的 iPad 键盘而不是我的弹出框。第二个示例使用委托 popoverController 而我的控制器是flipsidePopoverController.

我可以使用这样的 IBAction 吗?

- (IBAction)togglePopover:(id)sender {
  if (self.flipsidePopoverController) {
    [self.flipsidePopoverController dismissPopoverAnimated:YES];
    self.flipsidePopoverController = nil;
  } else {
    [self performSegueWithIdentifier:@"showAlternate" sender:sender];
  }
}
4

0 回答 0