library insets

This commit is contained in:
Chris Li 2016-09-15 15:38:48 -04:00
parent 624d2893a2
commit 66905eccd7
6 changed files with 233 additions and 246 deletions

View File

@ -10,9 +10,8 @@ import UIKit
import CoreData
import DZNEmptyDataSet
class DownloadTasksController: UIViewController, UITableViewDelegate, UITableViewDataSource, NSFetchedResultsControllerDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
class DownloadTasksController: UITableViewController, NSFetchedResultsControllerDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
@IBOutlet weak var tableView: UITableView!
var timer: NSTimer?
// MARK: - Override
@ -27,14 +26,12 @@ class DownloadTasksController: UIViewController, UITableViewDelegate, UITableVie
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
tableView.tableFooterView = UIView()
tableView.estimatedRowHeight = 90.0
tableView.rowHeight = UITableViewAutomaticDimension
tableView.emptyDataSetSource = self
tableView.emptyDataSetDelegate = self
tableView.tableFooterView = UIView()
tableView.estimatedRowHeight = 90.0
tableView.rowHeight = UITableViewAutomaticDimension
}
override func viewWillAppear(animated: Bool) {
@ -65,6 +62,15 @@ class DownloadTasksController: UIViewController, UITableViewDelegate, UITableVie
}
}
override func traitCollectionDidChange(previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
let top = tabBarController!.navigationController!.navigationBar.frame.maxY
let bottom = tabBarController!.tabBar.frame.height
let inset = UIEdgeInsets(top: top, left: 0, bottom: bottom, right: 0)
tableView.contentInset = inset
tableView.scrollIndicatorInsets = inset
}
// MARK: - Methods
func refreshProgress() {
@ -81,16 +87,16 @@ class DownloadTasksController: UIViewController, UITableViewDelegate, UITableVie
// MARK: - TableView Data Source
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return fetchedResultController.sections?.count ?? 0
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
guard let sectionInfo = fetchedResultController.sections?[section] else {return 0}
return sectionInfo.numberOfObjects
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
self.configureCell(cell, atIndexPath: indexPath)
return cell
@ -134,19 +140,19 @@ class DownloadTasksController: UIViewController, UITableViewDelegate, UITableVie
// MARK: Other Data Source
func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
guard tableView.numberOfSections > 1 else {return nil}
guard let languageName = fetchedResultController.sections?[section].name else {return nil}
return languageName
}
func sectionIndexTitlesForTableView(tableView: UITableView) -> [String]? {
override func sectionIndexTitlesForTableView(tableView: UITableView) -> [String]? {
let sectionIndexTitles = fetchedResultController.sectionIndexTitles
guard sectionIndexTitles.count > 2 else {return nil}
return sectionIndexTitles
}
func tableView(tableView: UITableView, sectionForSectionIndexTitle title: String, atIndex index: Int) -> Int {
override func tableView(tableView: UITableView, sectionForSectionIndexTitle title: String, atIndex index: Int) -> Int {
return fetchedResultController.sectionForSectionIndexTitle(title, atIndex: index)
}
@ -164,13 +170,13 @@ class DownloadTasksController: UIViewController, UITableViewDelegate, UITableVie
// header.textLabel?.font = UIFont.boldSystemFontOfSize(14)
// }
//
func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {}
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {}
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
guard let downloadTask = self.fetchedResultController.objectAtIndexPath(indexPath) as? DownloadTask else {return nil}
var actions = [UITableViewRowAction]()

View File

@ -45,6 +45,10 @@ extension DownloadTasksController {
return NSAttributedString(string: string, attributes: attributes)
}
func verticalOffsetForEmptyDataSet(scrollView: UIScrollView!) -> CGFloat {
return tabBarController!.navigationController!.navigationBar.frame.maxY
}
}
extension LocalBooksController {

View File

@ -11,9 +11,7 @@ import CoreData
import Operations
import DZNEmptyDataSet
class LocalBooksController: UIViewController, UITableViewDelegate, UITableViewDataSource, NSFetchedResultsControllerDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
@IBOutlet weak var tableView: UITableView!
class LocalBooksController: UITableViewController, NSFetchedResultsControllerDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
// MARK: - Override
@ -29,8 +27,6 @@ class LocalBooksController: UIViewController, UITableViewDelegate, UITableViewDa
tableView.emptyDataSetSource = self
tableView.emptyDataSetDelegate = self
tableView.delegate = self
tableView.dataSource = self
tableView.tableFooterView = UIView()
}
@ -54,18 +50,27 @@ class LocalBooksController: UIViewController, UITableViewDelegate, UITableViewDa
}
}
override func traitCollectionDidChange(previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
let top = tabBarController!.navigationController!.navigationBar.frame.maxY
let bottom = tabBarController!.tabBar.frame.height
let inset = UIEdgeInsets(top: top, left: 0, bottom: bottom, right: 0)
tableView.contentInset = inset
tableView.scrollIndicatorInsets = inset
}
// MARK: - TableView Data Source
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return fetchedResultController.sections?.count ?? 0
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
guard let sectionInfo = fetchedResultController.sections?[section] else {return 0}
return sectionInfo.numberOfObjects
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
self.configureCell(cell, atIndexPath: indexPath)
return cell
@ -84,43 +89,43 @@ class LocalBooksController: UIViewController, UITableViewDelegate, UITableViewDa
// MARK: Other Data Source
func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
guard tableView.numberOfSections > 1 else {return nil}
guard let languageName = fetchedResultController.sections?[section].name else {return nil}
return languageName
}
func sectionIndexTitlesForTableView(tableView: UITableView) -> [String]? {
override func sectionIndexTitlesForTableView(tableView: UITableView) -> [String]? {
let sectionIndexTitles = fetchedResultController.sectionIndexTitles
guard sectionIndexTitles.count > 2 else {return nil}
return sectionIndexTitles
}
func tableView(tableView: UITableView, sectionForSectionIndexTitle title: String, atIndex index: Int) -> Int {
override func tableView(tableView: UITableView, sectionForSectionIndexTitle title: String, atIndex index: Int) -> Int {
return fetchedResultController.sectionForSectionIndexTitle(title, atIndex: index)
}
// MARK: - Table View Delegate
func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
override func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
guard tableView.numberOfSections > 1 else {return 0.0}
guard let headerText = self.tableView(tableView, titleForHeaderInSection: section) else {return 0.0}
guard headerText != "" else {return 0.0}
return 20.0
}
func tableView(tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
override func tableView(tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
guard let header = view as? UITableViewHeaderFooterView else {return}
header.textLabel?.font = UIFont.boldSystemFontOfSize(14)
}
func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {}
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {}
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
let delete = UITableViewRowAction(style: .Destructive, title: LocalizedStrings.remove) { (action, indexPath) -> Void in
guard let book = self.fetchedResultController.objectAtIndexPath(indexPath) as? Book else {return}
let operation = RemoveBookConfirmationAlert(context: self, bookID: book.id)

View File

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

View File

@ -127,8 +127,8 @@
</tabBar>
<connections>
<segue destination="NBP-9l-DA2" kind="relationship" relationship="viewControllers" id="Zb0-fu-dUz"/>
<segue destination="7U1-44-aEc" kind="relationship" relationship="viewControllers" id="4Zm-9B-3Cv"/>
<segue destination="7F2-9D-s8D" kind="relationship" relationship="viewControllers" id="Gql-Nm-iFI"/>
<segue destination="BCO-3Y-FAM" kind="relationship" relationship="viewControllers" id="RXd-t8-KiP"/>
<segue destination="qBM-Wv-bKl" kind="relationship" relationship="viewControllers" id="EZU-xK-Qqa"/>
</connections>
</tabBarController>
<placeholder placeholderIdentifier="IBFirstResponder" id="fdG-uk-I8F" userLabel="First Responder" sceneMemberID="firstResponder"/>
@ -343,22 +343,16 @@
<point key="canvasLocation" x="724" y="-1203"/>
</scene>
<!--Download-->
<scene sceneID="Dfc-4k-8uO">
<scene sceneID="1qR-6w-kQ7">
<objects>
<viewController automaticallyAdjustsScrollViewInsets="NO" id="7U1-44-aEc" customClass="DownloadTasksController" customModule="Kiwix" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="kxT-1r-Dgp"/>
<viewControllerLayoutGuide type="bottom" id="g59-Ou-zU4"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Lfq-oN-mpU">
<tableViewController id="BCO-3Y-FAM" customClass="DownloadTasksController" customModule="Kiwix" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" id="D1O-qe-Bl5">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="8u2-KO-TvT">
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="Cell" rowHeight="82" id="ekT-ed-PU9" customClass="DownloadBookCell" customModule="Kiwix" customModuleProvider="target">
<rect key="frame" x="0.0" y="28" width="375" height="82"/>
<rect key="frame" x="0.0" y="92" width="375" height="82"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="ekT-ed-PU9" id="oM4-Hy-Mkf">
<frame key="frameInset" width="375" height="81"/>
@ -419,42 +413,28 @@
</connections>
</tableViewCell>
</prototypes>
</tableView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="trailing" secondItem="8u2-KO-TvT" secondAttribute="trailing" id="0KV-wg-nPy"/>
<constraint firstItem="g59-Ou-zU4" firstAttribute="top" secondItem="8u2-KO-TvT" secondAttribute="bottom" id="N3n-k9-dy1"/>
<constraint firstItem="8u2-KO-TvT" firstAttribute="top" secondItem="kxT-1r-Dgp" secondAttribute="bottom" id="ZgF-fK-J0u"/>
<constraint firstItem="8u2-KO-TvT" firstAttribute="leading" secondItem="Lfq-oN-mpU" secondAttribute="leading" id="pQk-Tb-XMY"/>
</constraints>
</view>
<tabBarItem key="tabBarItem" title="Download" id="k3e-zU-RVs"/>
<connections>
<outlet property="tableView" destination="8u2-KO-TvT" id="Sb0-Ir-O7u"/>
<outlet property="dataSource" destination="BCO-3Y-FAM" id="ohW-ms-gxP"/>
<outlet property="delegate" destination="BCO-3Y-FAM" id="Bhh-8w-y8W"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="3RF-Uc-QdV" userLabel="First Responder" sceneMemberID="firstResponder"/>
</tableView>
<tabBarItem key="tabBarItem" title="Download" id="uXY-g5-KJ0"/>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="XXA-3M-PVY" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="724" y="-2082.008995502249"/>
<point key="canvasLocation" x="724" y="-2082"/>
</scene>
<!--Local-->
<scene sceneID="d9I-Yb-VwG">
<scene sceneID="n4H-LQ-Cgx">
<objects>
<viewController automaticallyAdjustsScrollViewInsets="NO" id="7F2-9D-s8D" customClass="LocalBooksController" customModule="Kiwix" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="Cko-ed-ceh"/>
<viewControllerLayoutGuide type="bottom" id="Drp-Si-aLW"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="sGb-6r-dsG">
<tableViewController id="qBM-Wv-bKl" customClass="LocalBooksController" customModule="Kiwix" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" id="SRJ-5H-fny">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="Ofc-dk-yGh">
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="Cell" id="nka-b0-ZmD" customClass="BasicBookCell" customModule="Kiwix" customModuleProvider="target">
<rect key="frame" x="0.0" y="28" width="375" height="44"/>
<rect key="frame" x="0.0" y="92" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="nka-b0-ZmD" id="8e2-Je-FJO">
<frame key="frameInset" width="375" height="43"/>
@ -544,24 +524,16 @@
</connections>
</tableViewCell>
</prototypes>
</tableView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="Ofc-dk-yGh" firstAttribute="top" secondItem="Cko-ed-ceh" secondAttribute="bottom" id="6nu-oM-HF0"/>
<constraint firstItem="Ofc-dk-yGh" firstAttribute="leading" secondItem="sGb-6r-dsG" secondAttribute="leading" id="DsH-KT-BSc"/>
<constraint firstItem="Drp-Si-aLW" firstAttribute="top" secondItem="Ofc-dk-yGh" secondAttribute="bottom" id="WVQ-ZK-jfy"/>
<constraint firstAttribute="trailing" secondItem="Ofc-dk-yGh" secondAttribute="trailing" id="hNG-fK-7Bf"/>
</constraints>
</view>
<tabBarItem key="tabBarItem" title="Local" id="YcZ-Z5-yVM"/>
<connections>
<outlet property="tableView" destination="Ofc-dk-yGh" id="jPp-jZ-xVx"/>
<outlet property="dataSource" destination="qBM-Wv-bKl" id="EMc-50-xH7"/>
<outlet property="delegate" destination="qBM-Wv-bKl" id="rUg-8t-WVn"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="bcg-9M-Ggg" userLabel="First Responder" sceneMemberID="firstResponder"/>
</tableView>
<tabBarItem key="tabBarItem" title="Local" id="JyS-7n-rzC"/>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="RZa-7i-Vy7" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1644" y="-2082.008995502249"/>
<point key="canvasLocation" x="1644" y="-2082"/>
</scene>
<!--Language Filter Controller-->
<scene sceneID="IeL-6r-fE6">
@ -720,6 +692,6 @@
</scene>
</scenes>
<inferredMetricsTieBreakers>
<segue reference="N3M-rH-rAM"/>
<segue reference="YBq-US-fwE"/>
</inferredMetricsTieBreakers>
</document>

View File

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