1

UITextFields在一个UITableView(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];
}

附件是屏幕加载后立即截取的屏幕截图。您可以看到第三个文本字段已进入编辑模式。

文本字段的屏幕截图

4

2 回答 2

1

我会这样做的一种方法是将您的日期文本字段转换为自定义 UITableViewCell 中的 UIButton 并在用户触摸按钮时调出日期选择器。

当用户选择完日期后,更改按钮的标题以反映日期。

于 2012-06-05T03:58:24.250 回答
0

好的 - 发现了问题。在我的表格视图中,我有自定义 UITableViewCells 并且在那些自定义单元格中,出于某种原因,我有这种方法 -

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    [self.textField becomeFirstResponder];
}

这导致各个 tableviewcells 中的文本字段自动进入编辑模式。一旦我删除了这段代码,它就停止了。

于 2012-06-11T18:10:36.403 回答