我想添加一个secondTag
作为存储属性UITableView
。
但是当我尝试扩展UITableView
并像这样使用我的CustomTableView
时:
func tableView(_ tableView: CustomTableView , numberOfRowsInSection section: Int) -> Int
tableView协议(UITableViewDelegate
,UITableViewDataSource
(给了我一个错误,因为我没有遵循它的要求。
将secondTag
属性添加到UITabelView
有哪些选项?我应该覆盖表视图协议吗?我是否应该创建一个自定义表视图,UITableViewDataSource
其方法接受我的CustomTableView
作为函数的参数类型?
实现协议方法时,方法签名需要与协议中定义的类型匹配。 协议方法需要UITableView
,因此实现该函数签名,然后强制转换为函数内部的类型:
func tableView(_ tableView: UITableView , numberOfRowsInSection section: Int) -> Int {
guard let tableView = tableView as? CustomTableView else { return 0 }
// now you can access tableView.secondTag
}