我的UITextField
上有一个UITableViewCell
,供用户选择时间。我想按UIDatePicker
按UITextField
,但我的下面的代码无效。点击文本字段仍然显示默认键盘。
EditQuotaCell.h
@interface EditQuotaCell : UITableViewCell
@property (nonatomic, weak) id delegate;
@property (nonatomic, strong) IBOutlet UILabel *lblTimeRange;
@property (nonatomic, strong) IBOutlet UITextField *txtTimeStart;
@property (nonatomic, strong) IBOutlet UITextField *txtTimeEnd;
@property (nonatomic, strong) UIDatePicker *timePicker;
@end
EditQuotaCell.m
@implementation EditQuotaCell
@synthesize lblTimeRange;
@synthesize txtTimeStart, txtTimeEnd;
@synthesize timePicker;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (id) initWithCoder:(NSCoder *)aDecoder
{
if(self = [super initWithCoder:aDecoder])
{
self.timePicker = [[UIDatePicker alloc] init];
self.timePicker.datePickerMode = UIDatePickerModeDate;
[self.timePicker setDate:[NSDate date]];
[self.timePicker setMinuteInterval:30];
self.txtTimeStart.inputView = self.timePicker;
}
return self;
}
......
答案 0 :(得分:0)
请将您的选择器视图设置为viewdidload
中文本字段的输入视图txtTimeStart.inputView = timePicker;
答案 1 :(得分:0)
您可以尝试使用viewDidLoad:
方法
尝试在inputView
方法中为UITextField
设置viewDidLoad:
- (void)viewDidLoad
{
self.timePicker = [[UIDatePicker alloc] init];
self.timePicker.datePickerMode = UIDatePickerModeDate;
[self.timePicker setDate:[NSDate date]];
[self.timePicker setMinuteInterval:30];
self.txtTimeStart.inputView = self.timePicker;
}
答案 2 :(得分:0)
通过移动inputView
中的awakeFromNib
设置来解决此问题。
- (void) awakeFromNib
{
self.txtTimeStart.inputView = self.timePicker;
}