我的爲我的UITableViewCell
供用戶選擇時間。我想按UITextField
顯示UIDatePicker
,但我的下面的代碼不起作用。點擊文本框仍然會顯示默認的鍵盤。iOS:UIDatePicker在點擊UITextView時不顯示
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;
}
......
確實。但是因爲這是一個'UITableViewCell',它沒有'viewDidLoad'。我通過將它放入'awakeFromNib'來解決它。如果您可以更改答案,我可以將其標記爲正確。 – chongzixin
但是你可以在索引路徑的行中使用它。您應該在單元格中爲您的文本字段提供參考。 – jailani
在我的情況下,'UIDatePicker'是在'UITableViewCell'中指定的,它與'UITableViewController'文件是分開的。 – chongzixin