我正在开发一个非常基本的应用程序,当用户在 UITextField 中输入文本时会显示一个弹出框。不幸的是,弹出框没有出现,默认键盘出现了(不应该出现)。下面是我的相关代码:
NumberPadViewController.h
#import <UIKit/UIKit.h>
#import "NumberViewController.h"
@interface NumberPadViewController : UIViewController <UITextFieldDelegate> {
IBOutlet UITextField *numTest;
}
@property (nonatomic, strong) NumberViewController *numberPicker;
@property (nonatomic, strong) UIPopoverController *numberPickerPopover;
@end
NumberPadViewController.m
- (BOOL)textFieldShouldBeginEditing:(UITextField *) textField
{
// Create popover controller if nil
if(_numberPickerPopover == nil){ //make sure popover isn't displayed more than once in the view
_numberPickerPopover = [[UIPopoverController alloc]initWithContentViewController:_numberPicker];
}
[_numberPickerPopover presentPopoverFromRect:numTest.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
return NO;
}
我的弹出框类称为 NumberViewController.h
@interface NumberViewController : UIViewController {
}
@property (strong, nonatomic) IBOutlet UIButton *oneButton;
NumberViewController.m
#import "NumberViewController.h"
@interface NumberViewController ()
@end
@implementation NumberViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
NSInteger buttonHeight = _oneButton.frame.size.height * 4;
NSInteger buttonWidth = _oneButton.frame.size.width * 3;
self.contentSizeForViewInPopover = CGSizeMake(buttonWidth, buttonHeight);
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
我在 Storyboard 中创建了 UITextField,并在那里设置了委托。谁能看到我做错了什么?
提前感谢所有回复的人。