简体   繁体   English

如果用户单击单个视图控制器内的按钮,是否可以显示其他textField?

[英]Is there a way to display additional textFields if a user clicks on a button inside a single view controller?

I have a fairly complex form inside a view controller that requires a few text fields to be filled out for some users and many other text fields for other users. 我在视图控制器中有一个相当复杂的表单,该表单需要为一些用户填写一些文本字段,而为其他用户填写许多其他文本字段。 Is there a way to start the view controller with a couple of text fields, and then if a user clicks on a button('MORE')...the other text fields will display? 有没有一种方法可以使用几个文本字段来启动视图控制器,然后如果用户单击按钮(“更多”)...将显示其他文本字段?

You can add all the textFields in the View in Interface Builder and set the attribute myTextField.hidden = true . 您可以在Interface Builder中的View中添加所有textField,并设置属性myTextField.hidden = true When you click the more button then you can set the hidden attribute to false. 单击more按钮时,可以将hidden属性设置为false。

Hope that helps. 希望能有所帮助。

Is there a way to start the view controller with a couple of text fields, and then if a user clicks on a button('MORE')...the other text fields will display? 有没有一种方法可以使用几个文本字段来启动视图控制器,然后如果用户单击按钮(“更多”)...将显示其他文本字段?

Sure. 当然。 When the user taps the button, you can insert the additional fields. 当用户点击按钮时,您可以插入其他字段。 You might do that by creating the new fields and inserting them into the existing view, or loading some different view and setting the view controller's view to that new view (and of course populating the new view with the user's data). 您可以通过创建新字段并将其插入到现有视图中,或者加载一些不同的视图并将视图控制器的视图设置为该新视图(当然还要用用户的数据填充新视图)来做到这一点。 Or the fields in question could exist in the original view but be hidden. 或相关字段可能存在于原始视图中但被隐藏了。

A view controller is fully in charge of the view it manages, including all subviews of that view, so it can really do whatever it likes to move, add, or remove views, controls, etc. 一个视图控制器完全负责它所管理的视图,包括该视图的所有子视图,因此它可以真正完成移动,添加或删除视图,控件等所需的操作。

Yes you can. 是的你可以。 You can add text field at runtime by dynamically creating them. 您可以在运行时通过动态创建文本字段来添加文本字段。 But there is another possibility to design these fields in a separate UIView using IB and add this UIView to ViewController.view whenever needed. 但是还有另一种可能性,可以使用IB在单独的UIView设计这些字段,并在需要时将此UIView添加到ViewController.view This way you will save the positioning effort of each textfield element. 这样,您将节省每个文本字段元素的定位工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Swift 5 - 需要帮助重新加载 web 查看视图 controller 1 在用户第二次单击标签栏按钮后 - Swift 5 - Need help reloading web view on view controller 1 after user clicks tab bar button for the second time 使用xcode中的单个按钮显示和隐藏标签文本字段 - display and hide labels textfields using single button in xcode 单击取消按钮时,搜索显示控制器消失 - Search display controller disappears on multiple clicks on cancel button 带有多个文本字段的内部滚动视图 - scrollview inside view with multiple textfields 在iOS 8中,什么是在视图控制器中除按钮之外的所有内容上添加手势识别器而不添加其他按钮的正确方法? - In iOS 8 what is the correct way to add a gesture recognizer on everything in my view controller except a button, without adding an additional button? 如果用户单击播放按钮,如何在AVAudioPlayer中显示加载指示器 - how to display loading indicator in AVAudioPlayer if user clicks the play button 当用户再次单击按钮时如何推迟隐藏视图? - How to postpone hiding view when user clicks button again? 当用户单击UIAlertView的“确定”按钮时,移动到另一个视图 - Move to another view when the user clicks on the OK button of the UIAlertView 将字符串分配给另一个视图控制器中的文本字段 - Assign strings to textfields in another view controller 仅当文本字段正确时才推送到新的视图控制器 - Push to new view controller only if textfields are correct
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM