UITextField自动开始编辑模式

时间:2012-06-05 03:46:35

标签: ios uitextfield uidatepicker

我在UITextFields(3个单独的行)中有三个UITableView。前两个是标准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];
}

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

Screenshot of textfield

2 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

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

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

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

相关问题