Swift:Instagram故事和饲料细胞样式

时间:2017-10-10 06:39:01

标签: ios swift uitableview uicollectionview

我正在尝试使用我所做的类别/故事栏来实现Letgo或类似Instagram的样式Feed。但是当我滚动浏览帖子时,它会在单元格内滚动,而不是整个视图。所以故事栏只是停留在那里直到我到达集合视图的末尾然后故事栏滚动但后退,因为细胞的行为就像没有足够的细胞。

这就是我实现细胞的原因。

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,并将帧的其余部分设置为Feed。一切都在常规视图控制器中。如果有更好的方法来解决这个问题,我也可以点击栏与我联系,我可以重新编程所有内容。

结构: 的ViewController

-tableView

-CategoriesCell(身高110)

- CollectionView(hor)

-PostsCell(如何使这个动态取决于CollectionView内容)

- CollectionView(ver)

1 个答案:

答案 0 :(得分:0)

它不滚动,因为只有2个单元格,如果有更多的单元格,表格视图可以滚动,而不是这种情况。

您将需要更改方法,因为您将无法在单元格中添加单元格,您必须在此单元格中添加单元格。例如,对于第0个用于类别的索引单元格,您必须添加单元格以在insta中显示数据。

对于类别/故事栏:使用集合视图,因为表格视图默认没有水平滚动,集合视图可以更加自定义。

对于Feed:您可以使用集合视图或表视图。单元格数量将是要显示的Feed数量,因此表格视图将滚动直到有Feed数据。

相关问题