我想学习如何让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];
}
}