简体   繁体   English

使用 Swift 创建基于数组的表视图

[英]Creating Table Views Based off an Array with Swift

Is there a way that would allow me to create tables within a view controller and then position them?有没有办法让我在视图控制器中创建表格然后定位它们? I have an array "items" that would output the total amount of TableViews -1.我有一个数组“items”,它会输出 TableViews -1 的总量。 So for instance if the array "items" contained 15 items, 14 TableViews would be created.因此,例如,如果数组“items”包含 15 个项目,则将创建 14 个 TableView。

Can you add n tableView s to a single view controller?您可以将n 个tableView添加到单个视图控制器吗? Yes, but it's not practical or reasonable to write the amount of code you'd need to manage a varying number of layouts and delegates.是的,但是编写管理不同数量的布局和委托所需的代码量是不切实际或不合理的。

A tableView is designed to scroll (sections or) rows of cells, not to show a single item on screen. tableView旨在滚动(部分或)单元格行,而不是在屏幕上显示单个项目。 If you are determined to layout each item, you would be better off using a (much lighter) custom view instead of a tableView .如果您决定布局每个项目,最好使用(更轻的)自定义view而不是tableView

However, a single UICollectionView can do what you want to do.但是,单个UICollectionView可以做您想做的事情。 Yes, you'd have to write some code to manage the flow layout, depending on the number of brackets it had to display, but you could easily manage a grid-based approach with each column (round) showing teams and score.是的,您必须编写一些代码来管理流程布局,具体取决于它必须显示的括号数量,但您可以轻松管理基于网格的方法,每列(轮)显示团队和分数。

This would certainly be more intuitive and practical to have a single scrollable region, where each bracket is able be selected and interacted with, instead of trying to add multiple tableViews to a view (controller).拥有单个可滚动区域肯定会更直观和实用,其中每个括号都可以被选择并与之交互,而不是尝试将多个 tableView 添加到视图(控制器)。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM