Я пытаюсь добавить UITextField в UIScrollView. Я не могу получить UITextField в UIScrollView, но нажатие на TextField ничего не делает. Я пробовал много вещей. Последнее, что я пробовал, это создать собственный ScrollView и проверить hitTest. Я установил его, чтобы сказать «НЕТ» на задержкахContentTouches независимо, и он все еще ничего не делает. Я устанавливаю userInteractionEnabled на TextField и все равно ничего. Я просмотрел все другие подобные вопросы, и ни у кого из них нет ответов.Не удается получить доступ к UITextField в UIScrollView
Код, показанный ниже, показывает мою попытку добавить ярлык и 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];
Что вы хотите ???? вы хотите добавить текстовое поле только в scrollview? – TheTiger