[英]Adding a UITableView as a subview to another UITableView
I am new to iOS development. 我是iOS开发的新手。 I have a UITableView (say TableA) which is a subview of another UITableView (say TableB).
我有一个UITableView(例如TableA),它是另一个UITableView(例如TableB)的子视图。 I am using auto layout to position TableA in TableB.
我正在使用自动布局将TableA放置在TableB中。 Now, this works fine on iOS8 but the auto layout breaks completely on iOS7 giving some NSInternalInconsistencyException.
现在,这在iOS8上可以正常工作,但是自动布局在iOS7上完全中断,给出了一些NSInternalInconsistencyException。 To get rid of that exception is to stop using AutoLayout.
要摆脱该异常,就是停止使用AutoLayout。
I went with this problem to an experienced iOS developer and that person told me that I should't be adding a subview to a UITableView since it is a private view. 我将这个问题交给了一位经验丰富的iOS开发人员,那个人告诉我,我不应该在UITableView中添加子视图,因为它是私有视图。 That is just plain wrong he said.
他说那完全是错误的。 Now I don't exactly get why is that wrong but I couldn't ask him further.
现在我不知道为什么会出错,但是我不能再问他了。 I want to understand why is it wrong.
我想了解为什么会出错。
UITableView and UICollectionView are specialized views that handle all of their own sub-view arrangement. UITableView和UICollectionView是专门的视图,可以处理所有自己的子视图排列。 Both use "cells" as subviews along with the main view background, etc.
两者都使用“单元格”作为子视图以及主视图背景等。
I'm not sure why you have a table in a table; 我不确定为什么在桌子上有桌子。 but I'm guessing what you are trying to achieve is to actually put TableB inside a cell of TableA.
但是我想您要达到的目的是将TableB实际放在TableA的单元格中。
Create a XIB of a small tableView and use it as your custom table cell. 创建一个小tableView的XIB并将其用作您的自定义表格单元格。 Create a subclass of UITableViewCell to handle the implementation.
创建UITableViewCell的子类来处理实现。 Somehow you'll have to provide a data source (and possibly delegate) for each "TableB" inside the cells of TableA.
您必须以某种方式为TableA单元内的每个“ TableB”提供数据源(并可能委托)。
You may want to ask yourself why you need a table inside a table; 您可能想问自己,为什么在表格内需要表格? often a simple custom table cell can accomplish complex data display - or even a UICollectionView with a custom UICollectionViewLayout can display some very nice tabulated data.
通常,一个简单的自定义表格单元格可以完成复杂的数据显示-甚至带有自定义UICollectionViewLayout的UICollectionView都可以显示一些非常好的列表数据。
You do not own UITableView implementation and you not supposed to add subviews into it by addSubview method since layout, subviews management and all internals done by UITableView. 您不拥有UITableView实现,并且由于布局,子视图管理以及UITableView完成的所有内部操作,因此不应该通过addSubview方法向其中添加子视图。 You can modify content of UITableView through provided extentability points in delegate and dataSource.
您可以通过委托和数据源中提供的可扩展性点来修改UITableView的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.