UITextField无法选择

时间:2014-11-08 22:30:29

标签: ios objective-c uitextfield textfield viewdidload

我正在尝试为我正在处理的应用创建一个登录屏幕。现在我有两个UITextFields,后面有一个图像视图。当我尝试单击文本字段以输入文本时,没有任何反应。我花了很多时间试图弄清楚这个问题,但找不到有类似问题的人。在我的LoginViewController的viewDidLoad方法中,我有以下代码:

`

    [super viewDidLoad];
    UIImageView *splashView = [[UIImageView alloc] initWithFrame:self.view.frame];
    splashView.image = [UIImage imageNamed:@"Default-568h@2x.png"];

    UITextField *username = [[UITextField alloc] initWithFrame:CGRectMake(90, 320, 140, 30)];
    username.placeholder = @"username";
    username.borderStyle = UITextBorderStyleRoundedRect;
    username.returnKeyType = UIReturnKeyDone;
    username.textAlignment = NSTextAlignmentLeft;
    username.userInteractionEnabled = YES;
    [splashView addSubview:username];

    UITextField *password = [[UITextField alloc] initWithFrame:CGRectMake(90, 365, 140, 30)];
    password.placeholder = @"password";
    password.borderStyle = UITextBorderStyleRoundedRect;
    password.textAlignment = NSTextAlignmentLeft;
    [splashView addSubview:password];

    [self.view addSubview:splashView];
`

任何帮助或建议都将不胜感激。

1 个答案:

答案 0 :(得分:0)

更改地点以添加图片:

  [super viewDidLoad];
UIImageView *splashView = [[UIImageView alloc] initWithFrame:self.view.frame];
splashView.image = [UIImage imageNamed:@"Default-568h@2x.png"];

 // The image behind
 [self.view addSubview:splashView];

UITextField *username = [[UITextField alloc] initWithFrame:CGRectMake(90, 320, 140, 30)];
username.placeholder = @"username";
username.borderStyle = UITextBorderStyleRoundedRect;
username.returnKeyType = UIReturnKeyDone;
username.textAlignment = NSTextAlignmentLeft;
username.userInteractionEnabled = YES;
// Change this
[self.view addSubview:username];

UITextField *password = [[UITextField alloc] initWithFrame:CGRectMake(90, 365, 140, 30)];
password.placeholder = @"password";
password.borderStyle = UITextBorderStyleRoundedRect;
password.textAlignment = NSTextAlignmentLeft;
//And change this
[self.view addSubview:password];

如果您是另一个textField的另一个图像,则首先添加视图。