将子视图添加到 UITableViewController 的视图
我有一个 UITableViewController 的自定义子类,它在表中具有可编辑的单元格。我使用 UITableViewController 是因为我得到了所有漂亮的代码,可以在键盘免费出现时将单元格移动到可见。
对于我的一种单元格类型,我有一个 UIPicker 来代替键盘。一切都运行良好,我有一个很好的动画来将其滑入和滑出,就像键盘一样。问题是,因为我将选择器添加为 UITableViewController 的视图属性的子视图,所以用户可以上下滚动 UIPicker。
我理解为什么会发生这种情况(我假设 view 属性被分配给 viewController 的 tableView 属性,因此我的选择器被添加到 tableView 的顶部,tableView 的父级是滚动视图)。我不确定最好/推荐的方法是什么。
我尝试将选择器添加到 UIViewController 视图的 superView 中,但没有骰子:
[myViewController.view.superView addSubView:myPicker];
我仍然想保留所有漂亮的键盘效果,但希望我的选择器表现得像键盘一样,向上滑动并保持固定位置,然后在完成后滑开。
任何帮助将不胜感激。
戴夫
I have a custom subclass of a UITableViewController which has a editable cells in the table. I use the UITableViewController because I get all the nice code that moves the cells to be visible when the keyboard appears for free.
For one of my cell types I have a UIPicker that appears in place of the keyboard. All works well and I have a nice animation to slide it in and out just like the keyboard. The problem is, because I added the picker as a subview the UITableViewController's view property it is possible for the user to scroll the UIPicker up and down.
I understand why this is happening (I assume the view property is assigned to the tableView property of the viewController and therefore my picker is being added on top of the tableView, which has a scroll view as its parent). What I am not sure is the best/recommendend way around this.
I tried adding the picker to the superView of the UIViewController's view but no dice:
[myViewController.view.superView addSubView:myPicker];
I still want to keep all the nice keyboard effects but would like my picker to behave like the keyboard, slide up and stay fixed in position and then slide away when done.
Any help would be greatly appreciated.
Dave
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您将 UITextView 用于 UIPicker,您可以尝试使用“inputView”,iOS 将为您管理动画和视图层次结构。
您还可以始终创建一个包含 UIView,它将包含 TableViewController 的 View 属性并向其添加 UIPicker。
祝你好运
If you are using UITextView for the UIPicker you can try and use the "inputView" and iOS will manage animation and view hierarchy for you.
You can also always create a containing UIView that will contain the TableViewController's View property and add the UIPicker to him.
Good luck
解决这个问题的一种方法是创建一个 UIActionSheet 的子类,其中包含一个选择器,并在需要时显示 actionSheet。至少我在类似情况下是这么做的。
One way to solve it is to create a subclass of
UIActionSheet
with a picker inside of it and display actionSheet when needed. At least it's what I did in similar situation.