札幌 3.0.0

札幌 3.0.0

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2018年8月
SPM支持SPM

nghialv, ra1028维护。



札幌 3.0.0

札幌

Language CocoaPods [Carthage compatible] (https://github.com/Carthage/Carthage) License Issues

cellmodel驱动的collectionview管理器

特性

  • 易于管理分区和单元格(重置/插入/附加/移除/更新)
  • 无需编写UICollectionViewDelegateUICollectionViewDataSource协议的代码
  • 无需关心单元格标识符
  • 通过尾部闭包处理单元格选择
  • 支持方法链式调用
  • 支持下标访问
  • 完整示例
快速示例
// viewController swift file

let sapporo = Sapporo(collectionView: self.collectionView)

let cellmodel = YourCellModel(title: "Title", des: "description") {
	println("Did select cell with title = \(title)")
}

let topSection = SASection()

sapporo
	.reset(topSection)
	.bump()

topSection
	.append(cellmodel)	// append a new cell model in datasource
	.bump()	// show the new cell in the collection view

topSection
	.remove(1...3)
	.bump()

topSection
	.move(fromIndex: 0, toIndex: 3)
	.bump()
// your cell swift file

class YourCellModel : SACellModel {
	let title: String
	let des: String

	init(title: String, des: String, selectionHandler: (SACell) -> Void) {
		self.title = title
		self.des = des
		super.init(cellType: YourCell.self, selectionHandler: selectionHandler)
	}
}

class YourCell : SACell, SACellType {
	typealias CellModel = YourCellModel

	@IBOutlet weak var titleLabel: UILabel!

	override func configure() {
		super.configure()

		guard let cellmodel = cellmodel else {
			return
		}

		titleLabel.text = cellmodel.title
      	}
	}

用法

  • 处理章节
// retrieve a section or create a new section if it doesn't already exist
let section = sapporo[0]
	
// inserting
sapporo.insert(section, atIndex: 1)
	 .bump()

// moving
sapporo.move(fromIndex: 1, toIndex: 5)
	.bump()

// removing
sapporo.remove(index)
	.bump()

// remove all data
sapporo.reset()
	.bump()

// handing section index by enum
enum Section: Int, SASectionIndexType {
	case top
	case center
	case bottom

	static let count = 3
}

let topSection = sapporo[Section.Top]
  • 处理单元格
// appending
sapporo[0]
	.append(cellmodel)	// append a cellmodel
	.bump()	// and bump to show the cell in the collection view

sapporo[TopSection]
	.append(cellmodels)	// append a list of cellmodels
	.bump()					

// by using section
let section = sapporo[Section.Top]
section
	.append(cellmodel)
	.bump()

// 2. inserting
section
	.insert(cellmodels, atIndex: 1)
	.bump()

section
	.insertBeforeLast(cellmodels)
	.bump()

// 3. reseting
section
	.reset(cellmodels)	// replace current data in section by the new data
	.bump()

section
	.reset()	// or remove all data in section
	.bump()

// 4. moving
section
	.move(fromIndex: 5, toIndex: 1)
	.bump()

// 5. removing
section
	.remove(1)
	.bump()

section
	.remove(cellmodel)
	.bump()

section
	.remove(2...5)
	.bump()

section
	.removeLast()
	.bump()

// updating cell
let cellmodel = section[1]
cellmodel.property = newData
cellmodel.bump()

// able to retrieve a cellmodel by indexpath
let cellmodel = sapporo[indexpath]
  • 注册单元格、标题、页脚、可复用视图
sapporo
	.registerCellByNib(CustomCell)
	.registerCell(SimpleCell)
	.registerSupplementaryViewByNib(HeaderView.self, kind: "SectionHeader")
  • 自定义布局

如果您要自定义集合视图的布局,只需创建 SALayout 的子类,并调用 setLayout 方法设置新的布局实例。

class CustomLayout: SALayout {
	// the implementation for your layout
}

let layout = CustomLayout()
sapporo.setLayout(layout)

安装

  • 使用 Carthage

    • 将 github nghialv/Sapporo 添加到您的 Cartfile
    • 运行 carthage update
  • 使用 CocoaPods

    • 将以下内容添加到您的 Podfile
     use_frameworks!
    
     target 'YOUR_TARGET_NAME' do
       pod 'Sapporo'
     end
    
    • 运行 pod install
  • 使用子模块

需求

  • iOS 9.0+
  • Xcode 9+
  • Swift 4

许可证

Sapporo 采用 MIT 许可证 发布。