YYTableViewManager 列表管理

一、簡介

YYTableViewManager 基于數據驅動頁面的理念,接管了UITableViewdelegatedataSource的邏輯,開發者只需要關心數據的處理,避免了冗長的判斷,讓代碼更加易于維護。

二、頁面介紹

  1. YYTableViewManager:列表管理者
  2. YYTableViewSection:列表 section,section 管理者
  3. YYTableViewItem:列表 item,cell 管理者
  4. YYBaseTableView:封裝列表

三、使用技巧

??? 1. YYTableViewManager去管理列表的 delegate 和 dataSource,開發者不需要關心

??? 2. cell 可使用XIB或者純代碼創建,都支持

??? 3. 集成了一些列表常用的功能,可直接調用

??? 4. YYBaseTableView集成了刷新,可直接使用

??? 5. 使用注意

自定義的cell需要注冊
創建的 YYTableViewSection 需要提前調用 add(section: #) 添加section ,要不然后續操作可能獲取不到section

四、使用示例

let tableView = YYBaseTableView(frame: CGRect(x: 0, y: gTitleBarHeight, width: KScreenW, height: KScreenH - gTitleBarHeight - gSafeAreaInsets.bottom), style: .plain)
self.view.addSubview(tableView)
/// 當有多個 section 時,最后一個屬性設置為FALSE
tableViewManager = YYTableViewManager(tableView: tableView, false)
tableViewManager.register(YYXIBTableViewCell.self)

let oneHeaderV = UIView()
oneHeaderV.backgroundColor = .gray
let oneFooterV = UIView()
oneFooterV.backgroundColor = .gray
let oneSection = YYTableViewSection(headerView: oneHeaderV, footerView: oneFooterV)
oneSection.headerHeight = 50
oneSection.footerHeight = 20
tableViewManager.add(section: oneSection)
for index in 0...5 {
    let item = YYTableViewItem("YYXIBTableViewCell")
    item.setCellWillDisplayHandler { callBackItem in
    }
    /// 添加左滑,刪除 cell
    item.setLeftSwipeActionsHandler(["刪除"]) { callBackItem, actionIndex in
         oneSection.delete([callBackItem], complection: nil)
    }
    oneSection.add(item: item)
tableViewManager.reload()
}

更多使用技巧下載Demo去體驗

github地址:https://github.com/SwimBoys/YYTableViewManager

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容