mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-27 13:59:04 -04:00
documentations
This commit is contained in:
parent
9f3a2e5b76
commit
7af508e492
@ -9,8 +9,12 @@
|
||||
import UIKit
|
||||
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)
|
||||
/**
|
||||
Base class for all controllers that use CoreData and tableView.
|
||||
|
||||
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)
|
||||
*/
|
||||
|
||||
class CoreDataTableBaseController: UIViewController, NSFetchedResultsControllerDelegate {
|
||||
@IBOutlet weak var tableView: UITableView!
|
||||
|
@ -9,21 +9,32 @@
|
||||
import UIKit
|
||||
import DZNEmptyDataSet
|
||||
|
||||
/**
|
||||
Base class for SearchBooksController and SearchResultController.
|
||||
|
||||
Provides:
|
||||
|
||||
- tableView inset handle
|
||||
- DZNEmptyDataSet refresh
|
||||
|
||||
when keyboard shows / hides
|
||||
*/
|
||||
|
||||
class SearchBaseTableController: UIViewController, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
|
||||
@IBOutlet weak var tableView: UITableView!
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidShow(_:)), name: NSNotification.Name.UIKeyboardDidShow, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(_:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidShow(notification:)), name: .UIKeyboardDidShow, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(notification:)), name: .UIKeyboardWillHide, object: nil)
|
||||
}
|
||||
|
||||
override func viewWillDisappear(_ animated: Bool) {
|
||||
super.viewWillDisappear(animated)
|
||||
tableView.emptyDataSetSource = nil
|
||||
tableView.emptyDataSetDelegate = nil
|
||||
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIKeyboardDidShow, object: nil)
|
||||
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIKeyboardWillHide, object: nil)
|
||||
NotificationCenter.default.removeObserver(self, name: .UIKeyboardDidShow, object: nil)
|
||||
NotificationCenter.default.removeObserver(self, name: .UIKeyboardWillHide, object: nil)
|
||||
}
|
||||
|
||||
override func viewDidAppear(_ animated: Bool) {
|
||||
@ -32,7 +43,7 @@ class SearchBaseTableController: UIViewController, DZNEmptyDataSetSource, DZNEmp
|
||||
tableView.emptyDataSetDelegate = self
|
||||
}
|
||||
|
||||
func keyboardDidShow(_ notification: Notification) {
|
||||
func keyboardDidShow(notification: Notification) {
|
||||
guard let userInfo = notification.userInfo as? [String: NSValue],
|
||||
let origin = userInfo[UIKeyboardFrameEndUserInfoKey]?.cgRectValue.origin else {return}
|
||||
let point = view.convert(origin, from: nil)
|
||||
@ -42,7 +53,7 @@ class SearchBaseTableController: UIViewController, DZNEmptyDataSetSource, DZNEmp
|
||||
tableView.reloadEmptyDataSet()
|
||||
}
|
||||
|
||||
func keyboardWillHide(_ notification: Notification) {
|
||||
func keyboardWillHide(notification: Notification) {
|
||||
tableView.contentInset = UIEdgeInsetsMake(0.0, 0, 0, 0)
|
||||
tableView.scrollIndicatorInsets = UIEdgeInsetsMake(0.0, 0, 0, 0)
|
||||
tableView.reloadEmptyDataSet()
|
||||
|
@ -15,16 +15,13 @@ class SearchContainer: UIViewController {
|
||||
@IBOutlet weak var scopeAndHistoryContainer: UIView!
|
||||
@IBOutlet weak var resultContainer: UIView!
|
||||
private var resultController: SearchResultController!
|
||||
|
||||
|
||||
var delegate: SearchContainerDelegate?
|
||||
|
||||
var searchText = "" {
|
||||
didSet {
|
||||
configureVisibility()
|
||||
startSearch()
|
||||
}
|
||||
@IBAction func handleDimViewTap(_ sender: UITapGestureRecognizer) {
|
||||
delegate?.didTapSearchDimView()
|
||||
}
|
||||
|
||||
// MARK: - Overrides
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
@ -40,6 +37,15 @@ class SearchContainer: UIViewController {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Search
|
||||
|
||||
var searchText = "" {
|
||||
didSet {
|
||||
configureVisibility()
|
||||
startSearch()
|
||||
}
|
||||
}
|
||||
|
||||
private func configureVisibility() {
|
||||
let shouldHideResults = searchText == ""
|
||||
scopeAndHistoryContainer.isHidden = !shouldHideResults
|
||||
@ -56,10 +62,6 @@ class SearchContainer: UIViewController {
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@IBAction func handleDimViewTap(_ sender: UITapGestureRecognizer) {
|
||||
delegate?.didTapSearchDimView()
|
||||
}
|
||||
}
|
||||
|
||||
protocol SearchContainerDelegate: class {
|
||||
|
@ -49,7 +49,7 @@
|
||||
</dict>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.8.3346</string>
|
||||
<string>1.8.3347</string>
|
||||
<key>ITSAppUsesNonExemptEncryption</key>
|
||||
<false/>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
|
@ -21,7 +21,7 @@
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.8.3346</string>
|
||||
<string>1.8.3347</string>
|
||||
<key>NSExtension</key>
|
||||
<dict>
|
||||
<key>NSExtensionMainStoryboard</key>
|
||||
|
Loading…
x
Reference in New Issue
Block a user