GMCoreDataMultipleSectionsTableVC 0.1.5

GMCoreDataMultipleSectionsTableVC 0.1.5

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最新发布2015年1月

Gaston Morixe 维护。



该子类允许您轻松处理 多个 NSFetchedResultControllers,每个都位于一个有自定义标题的节中。

如何使用

Drawing

未来

class YourTableViewController: CoreDataMultipleSourcesTableVC {

    var managedObjectContext: NSManagedObjectContext? {
        didSet{
            self.sectionTitles = [<# YOUR SECTION TITLES #>]
            self.fetchedResultsControllers = [<# YOUR FETCHED RESULTS CONTROLLERS #>]
        }
    }

    func setupFetch() {
      self.managedObjectContext = <# YOUR MANAGED OBJECT CONTEXT #>
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        setupFetch()
    }

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        var cell: UITableViewCell?

        switch(indexPath.section){
        case 0:
            cell = createCellExampleOne(tableView, forOriginalIndexPath: indexPath)
        case 1:
            cell = createCellExampleTwo(tableView, forOriginalIndexPath: indexPath)
        default:
            break
        }

        if cell == nil {
            cell = tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell?
            if cell == nil {
                cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "cell")
            }
        }

        return cell!
    }

    func createCellExampleOne(tableView: UITableView, forOriginalIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        var cell: UITableViewCell
        let indexPathComputed = NSIndexPath(forRow: indexPath.row, inSection: 0)

        if let c = self.tableView.dequeueReusableCellWithIdentifier("cellExampleOne") as UITableViewCell? {
            cell = c as UITableViewCell
        }else{
            cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "cellExampleOne")
        }

        let managedObject = self.fetchedResultsControllers[indexPath.section].objectAtIndexPath(indexPathComputed) as NSManagedObject

        cell.textLabel?.text = managedObject.title

        return cell
    }

    func createCellExampleTwo(tableView: UITableView, forOriginalIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        var cell: UITableViewCell
        let indexPathComputed = NSIndexPath(forRow: indexPath.row, inSection: 0)

        if let c = self.tableView.dequeueReusableCellWithIdentifier("cellExampleTwo") as UITableViewCell? {
            cell = c as UITableViewCell
        }else{
            cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "cellExampleTwo")
        }

        let managedObject = self.fetchedResultsControllers[indexPath.section].objectAtIndexPath(indexPathComputed) as NSManagedObject

        cell.textLabel?.text = managedObject.title

        return cell
    }    

}

允许混合 NSFetchedResultController 和自定义静态/动态数组

  • 允许具有多个分区的 NSFetchedResultsController 并合并所有内容
  • 帮助?

@_imton | [email protected]

关键词

TableViewController 中的多个 NSFechedResultsController

  • 在 UITableViewController 中混合静态和动态内容
  • 在 UITableViewController 中使用两个 NSFechedResultsController
  • CocoaPods 是由