1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- //
- // TSTableView.swift
- // TSLiveWallpaper
- //
- // Created by 100Years on 2025/1/4.
- //
- open class TSSimpleTableView : NSObject{
- open var cellID:String = "TSSimpleTableViewCell"
- open lazy var tableView:UITableView = {
- let tableView = UITableView()
- tableView.initBaseTableView(reuseClass: reuseClass, isUseMJRefresh: false, delegate: self)
- return tableView
- }()
-
- open var reuseClass:[String] = [] {
- didSet{
- if let string = reuseClass.first {
- cellID = string
- }
- tableView.registerCellClass(cellIds: reuseClass)
- }
- }
-
- open var dataArray:[TSBasicSectionModel] = [TSBasicSectionModel](){
- didSet{
- tableView.reloadData()
- }
- }
- }
- extension TSSimpleTableView : UITableViewDataSource, UITableViewDelegate {
-
- public func numberOfSections(in tableView: UITableView) -> Int {
- return dataArray.count
- }
-
- public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- if let sectionModel = dataArray.safeObj(At: section){
- return sectionModel.itemsArray.count
- }
- return 0
- }
-
- public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
- if let sectionModel = dataArray.safeObj(At: indexPath.section),let itemModel = sectionModel.itemsArray.safeObj(At: indexPath.row){
- return itemModel.height
- }
- return 0
- }
-
- public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCell(withIdentifier: cellID)
-
- if let cell = cell as? TSSimpleTableViewCell {
- if let sectionModel = dataArray.safeObj(At: indexPath.section),let itemModel = sectionModel.itemsArray.safeObj(At: indexPath.row){
- cell.itemModel = itemModel
- }
- return cell
- }
-
- return UITableViewCell()
- }
-
- public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- if let sectionModel = dataArray.safeObj(At: indexPath.section),let itemModel = sectionModel.itemsArray.safeObj(At: indexPath.row){
- itemModel.tapBlock?(itemModel,indexPath.row,nil)
- }
- }
- }
- open class TSSimpleTableViewCell: TSBaseTabViewCell {
- open var itemModel:TSBasicItemModel = TSBasicItemModel()
-
- open func didEndDisplaying(indexPath: IndexPath){
-
- }
- }
|