触摸另一个UITextField不起作用(有时)

时间:2013-12-09 18:18:54

标签: ios ios7 uitextfield

我有2个文本字段。在启动时,我可以在lbl和lbl2之间切换。但是在第一次单击后只有lbl工作,你必须在光标进入该文本字段之前在lbl2上点击10(+/-)次。怎么回事?

- (void)viewWillAppear:(BOOL)animated
{
    UITextField *lbl = [[UITextField alloc] initWithFrame:CGRectMake(24, 397, 266, 30)];

    [lbl setPlaceholder:@"E-mailadres"];
    [lbl setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];

    [lbl setBackgroundColor:[UIColor clearColor]];
    lbl.textColor = [UIColor whiteColor];
    [[self view] addSubview:lbl];

    CALayer* layer = [lbl layer];

    CALayer *bottomBorder = [CALayer layer];
    bottomBorder.borderColor = [UIColor whiteColor].CGColor;
    bottomBorder.borderWidth = 1;
    bottomBorder.frame = CGRectMake(-1, layer.frame.size.height-1, layer.frame.size.width, 1);
    [bottomBorder setBorderColor:[UIColor whiteColor].CGColor];
    [layer addSublayer:bottomBorder];


    UITextField *lbl2 = [[UITextField alloc] initWithFrame:CGRectMake(24, 450, 266, 30)];

    [lbl2 setPlaceholder:@"Wachtwoord"];
    [lbl2 setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
    [lbl2 setBackgroundColor:[UIColor clearColor]];
    lbl2.textColor = [UIColor whiteColor];
    lbl2.secureTextEntry = YES;
    [[self view] addSubview:lbl2];


    CALayer* layer2 = [lbl2 layer];

    CALayer *bottomBorder2 = [CALayer layer];
    bottomBorder2.borderColor = [UIColor whiteColor].CGColor;
    bottomBorder2.borderWidth = 1;
    bottomBorder2.frame = CGRectMake(-1, layer2.frame.size.height-1, layer2.frame.size.width, 1);
    [bottomBorder2 setBorderColor:[UIColor whiteColor].CGColor];
    [layer2 addSublayer:bottomBorder2];

    UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    myButton.frame = CGRectMake(24, 500, 266, 30); // position in the parent view and set the size of the button
    [myButton setTitle:@"INLOGGEN" forState:UIControlStateNormal];
    [myButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    // add targets and actions
    // add to a view
    [[self view] addSubview:myButton];

    CALayer *layer3 = myButton.layer;
    layer3.backgroundColor = [[UIColor whiteColor] CGColor];
    layer3.borderColor = [[UIColor whiteColor] CGColor];
    layer3.borderWidth = 1.0f;
    layer3.opacity = 0.6;

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];

}

1 个答案:

答案 0 :(得分:0)

看来两个文本字段都没有给代表。我不确定你可以在没有它的情况下使用它们 - 我从未尝试过。如果您没有代理人,在编辑会话结束时如何解除键盘?