我是ios的初学者......
在我的一项事件中,我创建了自定义 scrollView
并在其上创建了一些自定义 textField
..现在当我们点击textField
然后是我的自定义 tableView
打开,但此表与现有的 textField
混淆....如果我在 UIView
上添加此表然后它不滚动......所以如何覆盖 ScrollView textField
并使用 textField
滚动表格.....我已经声明了所有table delegates
并且表格正确显示,但出现滚动问题....
scrollview=[[UIScrollView alloc]initWithFrame:CGRectMake(0,60,320,540)];
[scrollview setContentSize:CGSizeMake(800,1500)];
scrollview.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
scrollview.autoresizesSubviews = YES;
scrollview.scrollEnabled = YES;
scrollview.delegate = self;
scrollview.directionalLockEnabled = YES;
scrollview.showsVerticalScrollIndicator = YES;
scrollview.showsHorizontalScrollIndicator = YES;
scrollview.autoresizesSubviews = YES;
scrollview.backgroundColor=[UIColor whiteColor];
[self.view addSubview:scrollview];
AdviseDr=[[UITextField alloc]initWithFrame:CGRectMake(150,110,140,30)];
AdviseDr.font = [UIFont boldSystemFontOfSize:15.0];
AdviseDr.borderStyle = UITextBorderStyleLine;
AdviseDr.clearButtonMode = UITextFieldViewModeWhileEditing;
AdviseDr.delegate =self;
AdviseDr.tag=1;
[scrollview addSubview:AdviseDr];
table_AdviseDoctor=[[UITableView alloc]initwithframe:CGRectMake(150,200,170,200)style:UITableViewStylePlain];
table_AdviseDoctor.delegate=self;
table_AdviseDoctor.dataSource=self;
table_AdviseDoctor.layer.borderWidth = 2.0;
table_AdviseDoctor.layer.borderColor = [UIColor grayColor].CGColor;
[self.view addSubview:table_AdviseDoctor];
table_AdviseDoctor.hidden=YES;
Medicalfacility=[[UITextField alloc]initWithFrame:CGRectMake(150,150,170,30)];
Medicalfacility.font = [UIFont boldSystemFontOfSize:15.0];
Medicalfacility.borderStyle = UITextBorderStyleLine;
Medicalfacility.delegate =self;
Medicalfacility.tag=2;
[scrollview addSubview:Medicalfacility];
[Medicalfacility addTarget:self action:@selector(btnpress1:)forControlEvents:UIControlEventEditingDidBegin];
最佳答案
更好的选择是当你点击 UITextField
那时还隐藏你的UITextField
所以您的 UITextField 不会与您的 UITableView
混淆当你 删除/隐藏 您的 UITableView
那个时候你的隐藏UITextField
再次取消隐藏( 隐藏 = NO )。否则有很多方法可以解决你的问题,我喜欢这个选项,所以我建议你。
其他选项是。
把你的 UITableView 放在 UIView 中,我希望你已经知道 UITableView 有自己的 ScrollView,所以你不需要放入/覆盖任何 scrollView。
当你点击 UITextFiled
在 UIScrollView
中那时你还设置了用户不能用 UIScrollView
做的限制。和 UITextField
还
(给 userInteraction = NO)。所以当你的 UITableView 隐藏时也给(给 userInteraction = YES)。
关于iphone - 如何覆盖ios中的ScrollView内容或改变焦点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17424615/