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