一、簡介
YYTableViewManager 基于數(shù)據(jù)驅(qū)動頁面的理念,接管了UITableView
的delegate
和dataSource
的邏輯,開發(fā)者只需要關(guān)心數(shù)據(jù)的處理,避免了冗長的判斷,讓代碼更加易于維護(hù)琅催。
二居凶、頁面介紹
- YYTableViewManager:列表管理者
- YYTableViewSection:列表 section,section 管理者
- YYTableViewItem:列表 item藤抡,cell 管理者
- YYBaseTableView:封裝列表
三侠碧、使用技巧
??? 1. YYTableViewManager去管理列表的 delegate 和 dataSource,開發(fā)者不需要關(guān)心
??? 2. cell 可使用XIB或者純代碼創(chuàng)建缠黍,都支持
??? 3. 集成了一些列表常用的功能弄兜,可直接調(diào)用
??? 4. YYBaseTableView集成了刷新,可直接使用
??? 5. 使用注意
自定義的cell需要注冊
創(chuàng)建的 YYTableViewSection 需要提前調(diào)用 add(section: #) 添加section 瓷式,要不然后續(xù)操作可能獲取不到section
四替饿、使用示例
let tableView = YYBaseTableView(frame: CGRect(x: 0, y: gTitleBarHeight, width: KScreenW, height: KScreenH - gTitleBarHeight - gSafeAreaInsets.bottom), style: .plain)
self.view.addSubview(tableView)
/// 當(dāng)有多個 section 時,最后一個屬性設(shè)置為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去體驗(yàn)