[英]UITableView inside a UITableView?
Is it OK to add a UITableView
as a subview of another UITableView
? 是否可以将
UITableView
添加为另一个UITableView
的子视图? Or, should I create a UIView
and add each UITableView
to it? 或者,我应该创建一个
UIView
并添加每个UITableView
吗?
For a ComposeTableViewController
with a typeahead, like in the iPhone's native Mail app, which approach would you recommend and why? 对于具有
ComposeTableViewController
,就像iPhone的本机Mail应用程序一样,您会推荐哪种方法?为什么?
Note: I prefer to construct things 100% programmatically (no Interface Builder). 注意:我更喜欢以编程方式100%构建事物(没有Interface Builder)。
Subclass UITableViewController
. 子类
UITableViewController
。
Then, to show the typeahead results, create and add a resultsTableView
as a subview of self.tableView
positioned directly underneath the the cell (of self.tableView
) with the typeahead text field. 然后,要显示预先输出结果,请创建并添加
resultsTableView
作为self.tableView
的子视图,该子视图直接位于具有typeahead文本字段的单元格( self.tableView
)下方。
The nice thing about this approach is that resultsTableView
scrolls with self.tableView
automatically. 这种方法的
resultsTableView
是resultsTableView
自动滚动self.tableView
。
But, is it OK to add a UITableView
as a subview of another UITableView
? 但是,将
UITableView
添加为另一个UITableView
的子视图是否可以?
Subclass UIViewController
. 子类
UIViewController
。
Create and add tableView
(custom property) as a subview of self.view
. 创建
tableView
(自定义属性)并将其添加为self.view
的子视图。
Create and add resultsTableView
also as a subview of self.view
. 创建并添加
resultsTableView
作为self.view
的子视图。
The annoying thing about this approach is that I have to reposition resultsTableView
manually anytime self.tableView
scrolls. 关于这种方法的烦人的事情是我必须在
self.tableView
滚动时手动重新定位resultsTableView
。
I think I'd prefer approach 1, but adding a UITableView
as a subview of another UITableView
just seems smelly to me. 我想我更喜欢方法1,但添加
UITableView
作为另一个UITableView
的子视图对我来说似乎很臭。
TableViews cannot have subviews. TableViews不能有子视图。 You can try adding a tableview as the view of a TableViewCell, but then you have to ask yourself how it would scroll, if you tried scrolling in the subtableview would it scroll the child tableview or the parent tableview?
你可以尝试添加一个tableview作为TableViewCell的视图,但是你必须问自己它是如何滚动的,如果你尝试滚动子表视图会滚动子tableview还是父tableview? It is much easier to present multiple tableviews within a view.
在视图中显示多个表视图要容易得多。 This can be done easily by setting your custom viewcontroller as the datasource of both tableviews contained within its view and then comparing the tableview pointer that is sent as a parameter of the datasource method to the two tableview pointers that are IVars of your custom view controller.
这可以通过将自定义viewcontroller设置为其视图中包含的两个tableview的数据源,然后将作为数据源方法的参数发送的tableview指针与作为自定义视图控制器的IVars的两个tableview指针进行比较来轻松完成。
Hold stuff like this in a container. 把这样的东西放在容器里。 Create a container view controller which only does typeahead.
创建一个只进行typeahead的容器视图控制器。 This container view controller will hold your main table view controller (and its table view) and it will hold the typeahead view controller (and its view).
此容器视图控制器将保存主表视图控制器(及其表视图),它将保存预先输入视图控制器(及其视图)。
It will keep the logic needed for the typeahead out of your main table view and as a bonus you might end up with a reusable typeahead container which could be applied to other views. 它将保持主表视图中输出所需的逻辑,作为奖励,您最终可能会使用可重复使用的预先输入容器,该容器可应用于其他视图。
Yes it is good to go for adding UITableView
in as a cell of another UITableView
. 是的,最好将
UITableView
添加为另一个UITableView
的单元格。
I had one issue and posted a question 我有一个问题并发布了一个问题
Multiple Views as subviews 多个视图作为子视图
And requirement was like a group of controls with list of other controls. 并且需求就像一组控件和其他控件列表。 I thought that time that it will be messy if i'm going to add
UITableView
as a cell of UITableView
. 我想那个时候,这将是混乱的,如果我要添加
UITableView
作为一个单元UITableView
。
What i found that... Boy !! 我发现了......男孩! it's how iOS meant to be.
这就是iOS的意思。 There is no any lag while doing this.
这样做没有任何滞后。
Tested for below functionalities: 测试以下功能:
UITableView
cell UITableView
单元格 UITableView
and reload both at the same time. UITableView
运行时数据源更新同时重新加载。 There is no any reason not to add subview UITableView
. 没有任何理由不添加子视图
UITableView
。
You can do it but it is against the principle of MVC. 你可以这样做,但这违反了MVC的原则。 You will be setting the delegate of a view to another view which is wrong.
您将视图的委托设置为另一个错误的视图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.