我在 UITableView
中有三个 UITextFields
(3 行)。前两个是标准的 UITextFields
,需要文本输入,但第三个需要数据输入并与 UIDatePicker
相关联。
问题陈述:
当屏幕加载时,第三个文本字段自动开始编辑并弹出日期选择器。这很烦人。我只希望屏幕在执行任何操作之前等待用户开始输入。请在下面找到我的 viewDidLoad
代码。非常感谢您的帮助/见解
- (void)viewDidLoad
{
[super viewDidLoad];
[scrollView setContentSize:CGSizeMake(320, 910)];
expirationDatePicker.hidden = YES;
expirationDatePicker.date = [NSDate date];
[expirationDatePicker addTarget:self
action:@selector(changeDateValue:)
forControlEvents:UIControlEventValueChanged];
[self configureView];
}
- (void)configureView
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0]; //Get the docs directory
NSString *filePath = [documentsPath stringByAppendingPathComponent:[self.detailItem cardName]];
filePath = [filePath stringByAppendingPathExtension:@".png"];
NSData *pngData = [NSData dataWithContentsOfFile:filePath];
imgPickerButton.imageView.image = [UIImage imageWithData:pngData];
}
附件是屏幕加载后立即截取的屏幕截图。可以看到第三个文本框进入了编辑模式。
最佳答案
我这样做的一种方法是将您的日期文本字段转换为自定义 UITableViewCell 中的 UIButton,并在用户触摸按钮时调出日期选择器。
当用户选择完日期后,更改按钮的标题以反射(reflect)日期。
关于ios - UITextField 自动开始编辑模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10891298/