我正在使用UIPicker填充UITextField而不是键盘。这很好,但我现在无法关闭UIPicker。我希望能够点击屏幕上的任何地方并关闭UIPicker。我已经尝试过每种触摸方法都不会触发。touchesBegan not called
setUserInteractionEnabled:YES。 不知道它是否有所作为,但我使用故事板
我应该在我的AppDelegate中设置一些东西来侦听触摸吗?
这里是我的.h
#import <UIKit/UIKit.h>
@interface RNMemberTableViewController : UITableViewController<UIPickerViewDataSource, UIPickerViewDelegate, UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UIPickerView *behaviorPicker;
@property (nonatomic, weak) IBOutlet UIDatePicker *dateOfRecordPicker;
@property (nonatomic, strong) NSArray *behaviorLevels;
@property (weak, nonatomic) IBOutlet UITextField *behaviorTextField;
@end
这里是一些实施的...
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view setUserInteractionEnabled:YES];
[self buildBehaviorPicker];
NSLog(@"Member View");
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"test");
[self.view touchesBegan:touches withEvent:event];
UITouch *touch = [touches anyObject];
int tCount = touch.tapCount;
NSLog(@"Touched %d", tCount);
}
- (void) buildBehaviorPicker
{
behaviorLevels = [[NSArray alloc] initWithObjects:@"Unsatisfactory", @"Needs Improvement", @"Satisfactory", @"Outstanding", nil];
UIPickerView *pickerView = [[UIPickerView alloc] init];
pickerView.dataSource = self;
pickerView.delegate = self;
[pickerView selectRow:2 inComponent:0 animated:NO];
self.behaviorTextField.inputView = pickerView;
}
在此先感谢 -Bob
鲍勃,如果你喜欢工作答案,相应地标记为“回答”。 – BonanzaDriver