UIScrollViewにUITextFieldを追加しようとしています。UIScrollViewでUITextFieldを取得できませんが、TextFieldをクリックしても何も起こりません。私はたくさんのことを試みました。私が最後に試したのは、カスタムScrollViewを作成し、hitTestをチェックすることでした。delaysContentTouchesに関係なく「NO」と設定しましたが、それでも何も実行されません。TextFieldにuserInteractionEnabledを設定しましたが、まだ何もありません。私は他のすべての同様の質問を調べましたが、どれも答えがありません。
以下のコードは、ラベルとTextFieldをUIViewに追加してから、そのUIViewをScrollViewに追加する試みを示しています。すべて視覚的に機能しますが、TextFieldは何もしません。
UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 100, 30)];
lbl.text = @"Sample";
[lbl setBackgroundColor:[UIColor clearColor]];
[lbl setTextColor:[UIColor blackColor]];
UITextField *txt = [[UITextField alloc] initWithFrame:CGRectMake(115, 0, 195, 30)];
txt.borderStyle = UITextBorderStyleRoundedRect;
txt.font = [UIFont systemFontOfSize:15];
//txt.placeholder = @"enter username";
txt.autocorrectionType = UITextAutocorrectionTypeNo;
txt.keyboardType = UIKeyboardTypeDefault;
txt.returnKeyType = UIReturnKeyNext;
txt.clearButtonMode = UITextFieldViewModeWhileEditing;
[txt canBecomeFirstResponder];
txt.delegate=self;
txt.userInteractionEnabled=TRUE;
[txt addTarget:self action:@selector(tfTouch:) forControlEvents:UIControlEventTouchUpInside];
txt.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
UIView *theView = [[UIView alloc] init];
theView.userInteractionEnabled=TRUE;
[theView addSubview:lbl];
[theView addSubview:txt];
[scrollView addSubview:theView];