私のプロジェクトでは、ビューをアプリのルート ビューとして設定しました。
このルート ビューのコントローラーには、次のような階層があります。
rootview --[addsubview]-- foregroundView --[addsubview]-- テキストフィールド
私はxibの代わりにコードでそれをしました。
その場合、テキストフィールドはフォーカスできません。画面上のテキストフィールドをクリックしても何も起こらなかったようです。しかし、私がそのように変更した場合:
rootview --[addsubview]-- foregroundView
rootview --[addsubview]-- テキストフィールド
すべてがうまくいきました。
foregroundView と textfield をまとめて作りたいので、前者の方が好みです。これについて考えている人はいますか?どうもありがとう。
これが私の問題のコアソースコードです:
//it's a viewController.m , it's view has been set as the root view for the app.
self.foregroundView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 140, 290, 250)];
UIImage *foregroundImage = [XYZImageProcessor resizeImage:[UIImage imageNamed:@"Texture0203.jpg"] toSize:CGSizeMake(275, 250)];
[self.view addSubview:self.foregroundView ];
self.nickNameTextField = [self.class customTextFieldMake:CGRectMake(80, 200, 150, 30)];
[self.view addSubview:self.nickNameTextField];
//if I change it to [self.foregroundView addSubview:self.nickNameTextField],the textfield can not be focused.