2012-06-05 56 views
1

我有三个UITextFieldsUITableView(3个单独的行)。前两个是标准UITextFields,需要输入文字,但第三个需要输入数据,并且与UIDatePicker关联。UITextField自动开始编辑模式

问题描述: 当屏幕加载时,第三个文本字段自动开始编辑并弹出日期选择器。这很烦人。我只想让屏幕在做任何事之前等待用户开始输入。请在下面找到我的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

+0

它处于编辑模式吗?它看起来像占位符文本....? – lnafziger

+0

我确实有默认值的文本字段,但为什么该文本字段进入编辑模式?这是一旦屏幕加载,光标在该文本字段和日期选择器变得可见 – ChicagoSky

+0

更新:所以我继续,并在我的viewDidLoad方法的底部添加一行说[expirationDateTextField resignFirstResponder],但然后上面的文本字段进入编辑模式。我只想让屏幕在没有任何文本字段进入编辑模式的情况下完全可见。这不可能吗? – ChicagoSky

回答

0

好的 - 发现问题了。在我tableviews我有自定义UITableViewCells并在这些定制单元,我由于某种原因,有这个方法 -

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

这是造成个人tableviewcells的文本框自动进入编辑模式。一旦我删除了这段代码,它就不再那么做了。

1

一种方法是你的约会对象的文本字段转换成一个UIButton在一个自定义的UITableViewCell和弹出日期选取器,当用户触摸按钮。

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

相关问题