【问题标题】:How replace a table view by a collection view?如何用集合视图替换表格视图?
【发布时间】:2019-05-26 07:15:51
【问题描述】:

我想用集合视图替换表格视图,表格视图位于 XLPagerTabStrip 的选项卡内。

我已经尝试替换一些东西,但我得到了一些错误,有人可以让我朝着正确的方向前进吗?

import UIKit
import XLPagerTabStrip

class BooksChildViewController: UITableViewController, 
IndicatorInfoProvider {

    let cellIdentifier = "postCell"
    var blackTheme = false
    var itemInfo = IndicatorInfo(title: "Livros")

    init(style: UITableViewStyle, itemInfo: IndicatorInfo) {
        self.itemInfo = itemInfo
        super.init(style: style)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func viewDidLoad() {
        super.viewDidLoad()

    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

    }

    // MARK: - IndicatorInfoProvider

    func indicatorInfo(for pagerTabStripController:
PagerTabStripViewController) -> IndicatorInfo {
        return itemInfo
    }

}

【问题讨论】:

  • 如果你需要一个Collectionview,你为什么要创建一个UITableViewController?你需要在你的 UI 中同时使用这两者吗?您应该从简单的 UIViewController 继承您的 Viewcontroller,并使其适应 TableView 和 CollectionView 委托/数据源。

标签: ios swift uicollectionview tableview xlpagertabstrip


【解决方案1】:

您的类 BooksChildViewController 应该继承 UICollectionViewController 而不是 UITableViewController

另外,您需要修改您的 init()UICollectionViewController 可以用UICollectionViewLayout 代替UITableViewController 之类的样式作为初始化器。

【讨论】:

  • 是的,实际上我试过了,但它说:Argument labels '(style:)' do not match any available overloads
  • 我认为是因为 UICollectionView 类的构造函数没有“style”参数。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-25
  • 2023-04-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多