为什么UITextField成为firstResponder返回NO? [英] Why UITextField becomeFirstResponder returns NO?

查看:119
本文介绍了为什么UITextField成为firstResponder返回NO?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

while (true) {
    if ([identificationField becomeFirstResponder]) {

        NSLog(@"finally!");
        break;
    }
    else{
        if ([identificationField canBecomeFirstResponder]) {
            NSLog(@"can");
        }
        else{
            NSLog(@"cannot");
        }
        NSLog(@"%@", identificationField);
        NSLog(@"dadgum!!");

    }
}

这是它记录的内容:

   2014-02-05 11:33:54.253 Store Test[22488:70b] can

   2014-02-05 11:33:54.254 Store Test[22488:70b] <UITextField:
   0xb5c89a0; frame = (10 1; 300 43); text = ''; clipsToBounds = YES;
   opaque = NO; autoresize = TM+BM; gestureRecognizers = <NSArray:
   0xb5cc7b0>; layer = <CALayer: 0xb5c8b40>>

   2014-02-05 11:33:54.254 Store Test[22488:70b] dadgum!!

有人知道为什么会这样做吗?如您所见,文本字段可以成为第一响应者,只是不会.

Does anyone know why it might do that? As you can see, the text field can become the first responder, it just won't.

推荐答案

您的IdentificationField是否在UIView层次结构中?如果尚未将其添加到窗口中并显示出来,则它不能成为第一响应者.

Is your identificationField in UIView hierarchy? If it hasn't added into window and shown it cannot became first responder.

这篇关于为什么UITextField成为firstResponder返回NO?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆