This commit is contained in:
Chris Li 2016-11-26 18:43:18 -05:00
parent 7af508e492
commit 72e22c1ff2
5 changed files with 7 additions and 45 deletions

View File

@ -14,6 +14,7 @@ import CoreData
Yes, I know it'd be better to make this into a protocol.
But unfortunately, UIKit cannot seems to be able to recognize default protocol implementation in Swift. (iOS 10.1)
More spedifically, protocol extension is a swift only feature and is not visible to objc_msgSend()
*/
class CoreDataTableBaseController: UIViewController, NSFetchedResultsControllerDelegate {

View File

@ -20,8 +20,8 @@ import DZNEmptyDataSet
when keyboard shows / hides
*/
class SearchBaseTableController: UIViewController, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
@IBOutlet weak var tableView: UITableView!
class SearchBaseTableController: CoreDataTableBaseController, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
// @IBOutlet weak var tableView: UITableView!
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

View File

@ -10,7 +10,7 @@ import UIKit
import CoreData
import DZNEmptyDataSet
class SearchBooksController: SearchBaseTableController, UITableViewDelegate, UITableViewDataSource, NSFetchedResultsControllerDelegate, TableCellDelegate {
class SearchBooksController: SearchBaseTableController, UITableViewDelegate, UITableViewDataSource, TableCellDelegate {
@IBOutlet weak var recentSearchContainer: DropShadowView!
@IBOutlet weak var recentSearchBarHeight: NSLayoutConstraint!
@ -61,7 +61,7 @@ class SearchBooksController: SearchBaseTableController, UITableViewDelegate, UIT
return cell
}
func configureCell(_ cell: UITableViewCell, atIndexPath indexPath: IndexPath) {
override func configureCell(_ cell: UITableViewCell, atIndexPath indexPath: IndexPath) {
guard let cell = cell as? CheckMarkBookCell else {return}
let book = fetchedResultController.object(at: indexPath)
@ -101,45 +101,6 @@ class SearchBooksController: SearchBaseTableController, UITableViewDelegate, UIT
GlobalQueue.shared.add(articleLoadOperation: operation)
}
// MARK: - Fetched Result Controller Delegate
func controllerWillChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
tableView.beginUpdates()
}
func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange sectionInfo: NSFetchedResultsSectionInfo, atSectionIndex sectionIndex: Int, for type: NSFetchedResultsChangeType) {
switch type {
case .insert:
tableView.insertSections(IndexSet(integer: sectionIndex), with: .fade)
case .delete:
tableView.deleteSections(IndexSet(integer: sectionIndex), with: .fade)
default:
return
}
}
func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) {
switch type {
case .insert:
guard let newIndexPath = newIndexPath else {return}
tableView.insertRows(at: [newIndexPath], with: .fade)
case .delete:
guard let indexPath = indexPath else {return}
tableView.deleteRows(at: [indexPath], with: .fade)
case .update:
guard let indexPath = indexPath, let cell = tableView.cellForRow(at: indexPath) else {return}
configureCell(cell, atIndexPath: indexPath)
case .move:
guard let indexPath = indexPath, let newIndexPath = newIndexPath else {return}
tableView.deleteRows(at: [indexPath], with: .fade)
tableView.insertRows(at: [newIndexPath], with: .fade)
}
}
func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
tableView.endUpdates()
}
// MARK: - DZNEmptyDataSet
func titleForEmptyDataSet(_ scrollView: UIScrollView!) -> NSAttributedString! {

View File

@ -49,7 +49,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>1.8.3347</string>
<string>1.8.3350</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSRequiresIPhoneOS</key>

View File

@ -21,7 +21,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.8.3347</string>
<string>1.8.3350</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionMainStoryboard</key>