我正在使用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