ios - Swift:Instagram 故事和 Feed Cell 风格

标签 ios swift uitableview uicollectionview

我正在尝试使用我已经完成的类别/故事栏来实现 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/

相关文章:

ios - 从 XML/数组创建 map 图钉

iphone - 删除范围内 NSMutableArray 的对象

ios - 如何以编程方式在 iOS 中实现即时标记功能

ios - minimumInteritemSpacing 在 Collection View 的末尾添加了一些奇怪的内容

ios - 传递从自定义 tableView Cell 定义的对象

iphone - UITableview 调整大小动画

ios - 地址簿链接器错误 : Undefined symbols for architecture i386

ios - iOS6 中使用 QLPreviewController 渲染上下文的问题

ios - 方法中返回 Json 对象,无法将 NSDictionary 转换为 Void

iphone - 获取 UITableViewCell 文本的正确方法