如何使用UITableViewDelegate进行子类化 - Swift 3

时间:2016-11-07 12:45:40

标签: ios uitableview swift3 subclass

假设我有一个名为Open的{​​{1}}类,它存在于框架内。这个类做了其他的事情,但也包括UITableView的实现......

MyClass是新的Open,意味着我应该能够从另一个模块中访问该类,并将其子类化。以下是一个示例类:

Public

现在,让我说我想继承MyClass,并添加UITableViewDelegates

open class TableViewEngine: NSObject {

   internal var tableView: UITableView!

   public init(tableView: UITableView) {
       super.init()
       self.tableView = tableView
       self.setupTableView()
   }

   fileprivate func setupTableView() {
       self.tableView.delegate = self
       self.tableView.dataSource = self
       self.tableView.separatorStyle = .none
   }
}

extension TableViewEngine: UITableViewDataSource {
   public func numberOfSections(in tableView: UITableView) -> Int {
       return 1
   }

   public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
       return 1
   }

   public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
       return UITableViewCell()
   }
}

我的问题是CustomClass从不调用添加的这些新添加的委托,因为它们在Apple的UITableViewDelegate中被定义为 public而不是open ,因此它们实际上从未被调用过(尽管它们是在预测的时候预测的)写作)。

在Swift 3推出打开之前,它曾经在Swift 3之前工作。

我如何解决这个问题?

0 个答案:

没有答案