ALTableView 0.3.6

ALTableView 0.3.6

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最后发布2019年5月

Lorenzo Villarroel维护。



  • Abimael Barea, Lorenzo Villarroel

ALTableView

安装

本项目的 Objective-C 部分已停止开发。最新的 Objective-C 代码稳定版本是 0.1.1

本框架仍在开发中。我们尚不能保证所有功能都能正常工作。

swift 的最新稳定版本是 0.3.4,其中包括对 swift 4.2 的支持

CocoaPods

要使用 CocoaPods 将 ALTableView 集成到您的 Xcode 项目中,请在 Podfile 中指定它

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'ALTableView', '~> 0.1.6'
end

或者,您也可以尝试将这些类添加到您的项目中。

需求

Swift 4.2 iOS 9.0

它是如何工作的

该框架是一个通用的UITableView数据源和数据委托,它将帮助您减少每次创建tableView时复制粘贴的所有代码。为了做到这一点,您只需创建一个SectionElement数组,并为每个一个创建一个RowElement数组。

SectionElement(表示UITableView的某个部分)

  • 提供你的自定义头部和尾部视图
  • 只需要一个布尔值就可以使您的部分可折叠

RowElement(包含一个UITableViewCell及其数据)

  • 我们为您创建单元格并绑定您提供的数据
  • 每个单元格都可以有不同的布局并执行不同的操作

创建您的单元格,我们将管理它们

简单易用,只需继承UITableViewCell实现这3个方法。

  • cellPressed接收到当前viewController,表示单元格被按下时的操作
  • cellCreated接收类似于参数的数据,您希望在单元格中显示的数据
  • cellDeselected当您的单元格被取消选中时调用
import UIKit
import ALTableView

class MasterTableViewCell: UITableViewCell, ALCellProtocol {
    
    static let nib = "MasterTableViewCell"
    static let reuseIdentifier = "MasterTableViewCellReuseIdentifier"
    
    @IBOutlet weak var labelText: UILabel!
    
    public func cellCreated(dataObject: Any) {
        if let title = dataObject as? String {
            self.labelText.text = title
        }
    }
    
    public func cellPressed(viewController: UIViewController?) {
        self.labelText.text = "Tapped"
    }
    
    func cellDeselected() {
        self.labelText.text = "Deselected"
    }
    
}

创建一个RowElement包含了您的单元格和数据

let rowElement = ALRowElement(className:MasterTableViewCell.classForCoder(), identifier: MasterTableViewCell.reuseIdentifier, dataObject: "Cell text", estimateHeightMode: true)

如果您不想实现这3个方法,可以使用块

let rowElement = ALRowElement(className: MasterTableViewCell.classForCoder(), identifier: MasterTableViewCell.reuseIdentifier, dataObject: "Cell text", estimateHeightMode: true, pressedHandler: { (viewController, cell) in
                if let cell = cell as? MasterTableViewCell {
                    cell.labelText.text = "Tapped"
                }
                
            }, createdHandler: { (dataObject, cell) in
                if let title = dataObject as? String, let cell = cell as? MasterTableViewCell {
                    cell.labelText.text = title
                }
            }) { (cell) in
                if let cell = cell as? MasterTableViewCell {
                    cell.labelText.text = "Deselected"
                }
            }

ALTableView示例

import UIKit
import ALTableView

class MasterViewController: UITableViewController {
    
    var alTableView: ALTableView?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        let sectionElements = self.createElements()
        
        self.alTableView = ALTableView(sectionElements: sectionElements, viewController: self, tableView: self.tableView)
        self.registerCells()
        self.tableView.delegate = self.alTableView
        self.tableView.dataSource = self.alTableView
        self.tableView.reloadData()
    }
    
    func createElements() -> [ALSectionElement] {
        var sectionElements = [ALSectionElement]()
        for _ in 0...2 { //Typically you will iterate over your datasource
            var rowElements = Array<ALRowElement>()
            let rowElement = ALRowElement(className:MasterTableViewCell.classForCoder(), identifier: MasterTableViewCell.reuseIdentifier, dataObject: "Cell text", estimateHeightMode: true)
            rowElements.append(rowElement)

            let section = ALSectionElement(rowElements: rowElements, headerElement: nil, footerElement: nil, isExpandable: true)
            sectionElements.append(section)
        }
        
        return sectionElements
    }
    
    func registerCells() {
        self.alTableView?.registerCell(nibName: MasterTableViewCell.nib, reuseIdentifier: MasterTableViewCell.reuseIdentifier)

    }
}

作者

Abimael Barea @elabi3 - Lorenzo Villarroel @lorencr7

许可协议

The MIT License (MIT)

Copyright (c) 2015 ALiOSDev

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.