测试已测试 | ✗ |
语言语言 | Obj-CObjective C |
许可证 | MIT |
发布最新发布 | 2015年1月 |
由 Gaston Morixe 维护。
该子类允许您轻松处理 多个 NSFetchedResultControllers,每个都位于一个有自定义标题的节中。
如何使用
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
}
}
关键词