我正在尝试使用我已经完成的类别/故事栏来实现 Letgo 或类似 Instagram 的风格提要。但是当我滚动浏览帖子时,它仅在单元格内滚动,而不是作为整个 View 。因此,故事栏一直停留在那里,直到我到达 Collection View 的末尾,然后故事栏滚动,但又向下滚动,因为单元格表现得好像没有足够的单元格。
这就是我所拥有的,所以要实现单元格。
override func viewDidLoad() {
super.viewDidLoad()
self.automaticallyAdjustsScrollViewInsets = false
self.tableView.dataSource = self
self.tableView.delegate = self
}
// MARK: - UITableViewDatasourse
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 2
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch indexPath.row {
case 0:
return tableView.dequeueReusableCell(withIdentifier: "categoryCell", for: indexPath) as! CategoryTableViewCell
default:
return tableView.dequeueReusableCell(withIdentifier: "productCell", for: indexPath) as! ProductTableViewCell
}
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
switch indexPath.row {
case 0:
return 110
default:
return tableView.frame.height - 110
}
}
我将类别栏的高度设置为 110,框架的其余部分用于提要。一切都在常规 View Controller 中。如果有更好的方法来解决这个问题,我也可以点击栏与提要交互,我愿意重新编程一切。
结构: View Controller
-TableView
—CategoriesCell(高度 110)
——CollectionView(水平)
—PostsCell(如何根据 CollectionView 内容使其动态化)
——CollectionView(版本)
最佳答案
它不会滚动,因为只有 2 个单元格,如果有更多单元格,表格 View 可以滚动,但本例中情况并非如此。
您将需要更改方法,因为您将无法在单元格中添加单元格,而您必须在此执行此操作。例如,对于用于类别的第 0 个索引单元格,您必须添加单元格来显示数据,如 insta 中所示。
对于类别/故事栏:使用 Collection View ,因为 TableView 默认没有水平滚动,并且 Collection View 可以进行更多自定义。
对于 feed :您可以使用 Collection View 或 TableView 来实现此目的。单元格的数量将是要显示的提要的数量,因此表格 View 将滚动,直到出现提要数据。
关于ios - Swift:Instagram 故事和 Feed Cell 风格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46660114/