Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gastonmorixe/gmcoredatamultiplesectionstablevc
UITableViewController subclass that handles multiple NSFetchedResultsControllers
https://github.com/gastonmorixe/gmcoredatamultiplesectionstablevc
Last synced: 17 days ago
JSON representation
UITableViewController subclass that handles multiple NSFetchedResultsControllers
- Host: GitHub
- URL: https://github.com/gastonmorixe/gmcoredatamultiplesectionstablevc
- Owner: gastonmorixe
- License: mit
- Created: 2014-12-30T10:47:12.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-01-24T07:58:24.000Z (almost 10 years ago)
- Last Synced: 2024-10-21T00:01:04.281Z (18 days ago)
- Language: Objective-C
- Homepage:
- Size: 703 KB
- Stars: 10
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
GMCoreDataMultipleSectionsTableVC
=================================UITableViewControllers are most of the time backed with only one NSFetchedResultsController.
This subclass allows you to easily handle **multiple NSFetchedResultsControllers**, each under a section with a custom title.
How To Use It
--````swift
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
}}
````Future
--- Allow Mix of NSFetchedResultController & Custom Static/Dynamic Arrays
- Allow NSFetchedResultsController with multiple sections and merge allHelp?
--
[@_imton](http://twitter.com/_imton) | [[email protected]](mailto:[email protected])Keywords
--
- Multiple NSFechedResultsController in UITableViewController
- Mix Static and Dynamic content on UITableViewController
- Two NSFechedResultsController in UITableViewController