Added table view footer in home view controller, some code cleanup

This commit is contained in:
Raimund Wege committed 2016-08-01 11:02:19 +02:00
1 parent 6056613514
commit 05738fc42c
8 files changed
+84 -22

No files matched your search

@@ -22,6 +22,7 @@ class AboutViewController: UIViewController {
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
partnershipTextView.scrollRectToVisible(CGRect(x: 0, y: 0, width: 1, height: 1), animated: false)
}
@@ -55,8 +56,8 @@ class AboutViewController: UIViewController {
presentingViewController!.dismissViewControllerAnimated(true, completion: nil)
}
@IBAction func eulaButtonTapped(sender: AnyObject) {
UIApplication.sharedApplication().openURL(URLs.EULA)
@IBAction func termsButtonTapped(sender: AnyObject) {
UIApplication.sharedApplication().openURL(URLs.Terms)
}
}
@@ -13,7 +13,7 @@ struct Application {
}
struct URLs {
static let EULA = NSURL(string: "http://www.sapsailing.com/EULA_iOS_SailingBoatTracker.html")!
static let Terms = NSURL(string: "http://www.sapsailing.com/EULA_iOS_SailingBoatTracker.html") ?? NSURL()
}
struct Colors {
@@ -17,11 +17,14 @@ class HomeViewController: UIViewController {
static let Settings = "Settings"
}
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var headerView: UIView!
@IBOutlet weak var headerTitleLabel: UILabel!
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var scanCodeButton: UIButton!
@IBOutlet weak var noCodeButton: UIButton!
@IBOutlet weak var infoCodeLabel: UILabel!
@IBOutlet weak var footerView: UIView!
@IBOutlet weak var footerTextView: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
@@ -39,6 +42,11 @@ class HomeViewController: UIViewController {
unsubscribeFromNewCheckInURLNotifications()
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
layout()
}
// MARK: - Setup
private func setup() {
@@ -56,10 +64,11 @@ class HomeViewController: UIViewController {
private func setupLocalization() {
navigationItem.title = Application.Title
titleLabel.text = Translation.HomeView.TableView.Title.String
headerTitleLabel.text = Translation.HomeView.HeaderTitleLabel.Text.String
scanCodeButton.setTitle(Translation.ScanView.Title.String, forState: .Normal)
noCodeButton.setTitle(Translation.HomeView.NoCodeAlert.Title.String, forState: .Normal)
infoCodeLabel.text = Translation.HomeView.InfoCodeLabel.Text.String
footerTextView.text = Translation.HomeView.FooterTextView.Text.String
}
private func setupNavigationBar() {
@@ -79,7 +88,22 @@ class HomeViewController: UIViewController {
}
}
// MARK: - Reviews
// MARK: - Layout
private func layout() {
self.layoutFooterView()
}
private func layoutFooterView() {
let height = footerTextView.sizeThatFits(CGSizeMake(footerView.frame.width, CGFloat.max)).height
footerView.frame = CGRectMake(footerView.frame.origin.x,
footerView.frame.origin.y,
footerView.frame.width,
height
)
}
// MARK: - Review
private func reviews() {
self.reviewTerms({
@@ -93,7 +117,7 @@ class HomeViewController: UIViewController {
})
}
// MARK: - 1. Review Terms
// MARK: 1. Review Terms
private func reviewTerms(completion: () -> Void) {
guard Preferences.termsAccepted == false else { completion(); return }
@@ -102,7 +126,7 @@ class HomeViewController: UIViewController {
preferredStyle: .Alert
)
let showTermsAction = UIAlertAction(title: Translation.HomeView.TermsAlert.ShowTermsAction.Title.String, style: .Cancel) { action in
UIApplication.sharedApplication().openURL(URLs.EULA)
UIApplication.sharedApplication().openURL(URLs.Terms)
self.reviewTerms(completion) // Review terms until user accepted terms
}
let acceptTermsAction = UIAlertAction(title: Translation.HomeView.TermsAlert.AcceptTermsAction.Title.String, style: .Default) { action in
@@ -259,7 +283,17 @@ class HomeViewController: UIViewController {
extension HomeViewController: UITableViewDataSource {
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return fetchedResultsController.sections?[section].numberOfObjects ?? 0
let numberOfRows = fetchedResultsController.sections?[section].numberOfObjects ?? 0
if numberOfRows == 0 {
if tableView.tableHeaderView != nil {
tableView.tableHeaderView = nil
}
} else {
if tableView.tableHeaderView == nil {
tableView.tableHeaderView = headerView
}
}
return numberOfRows
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15G31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="pqQ-jd-OwW">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15G31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="pqQ-jd-OwW">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
@@ -52,6 +52,7 @@
<string>OpenSans</string>
<string>OpenSans</string>
<string>OpenSans</string>
<string>OpenSans</string>
</mutableArray>
<mutableArray key="OpenSans-Semibold.ttf">
<string>OpenSans-Semibold</string>
@@ -78,11 +79,11 @@
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="81" sectionHeaderHeight="22" sectionFooterHeight="22" translatesAutoresizingMaskIntoConstraints="NO" id="OXU-ft-TXZ">
<rect key="frame" x="0.0" y="0.0" width="600" height="330.5"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<view key="tableHeaderView" contentMode="scaleToFill" id="mhw-sY-eah" userLabel="Title View">
<view key="tableHeaderView" contentMode="scaleToFill" id="mhw-sY-eah" userLabel="Header View">
<rect key="frame" x="0.0" y="0.0" width="600" height="52"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Title Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" preferredMaxLayoutWidth="0.0" translatesAutoresizingMaskIntoConstraints="NO" id="lc2-1P-oDt">
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Title Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" preferredMaxLayoutWidth="0.0" translatesAutoresizingMaskIntoConstraints="NO" id="lc2-1P-oDt" userLabel="Header Title Label">
<rect key="frame" x="20" y="0.0" width="580" height="52"/>
<fontDescription key="fontDescription" name="OpenSans" family="Open Sans" pointSize="18"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
@@ -98,10 +99,24 @@
<constraint firstItem="lc2-1P-oDt" firstAttribute="leading" secondItem="mhw-sY-eah" secondAttribute="leading" constant="20" id="uqT-sU-EdP"/>
</constraints>
</view>
<view key="tableFooterView" contentMode="scaleToFill" id="ntQ-jE-XcH">
<rect key="frame" x="0.0" y="155" width="600" height="0.0"/>
<view key="tableFooterView" contentMode="scaleToFill" id="ntQ-jE-XcH" userLabel="Footer View">
<rect key="frame" x="0.0" y="155" width="600" height="52"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<subviews>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" scrollEnabled="NO" editable="NO" text="Footer Text View" textAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="FXc-cY-lmX">
<rect key="frame" x="0.0" y="0.0" width="600" height="52"/>
<fontDescription key="fontDescription" name="OpenSans" family="Open Sans" pointSize="16"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
<dataDetectorType key="dataDetectorTypes" link="YES"/>
</textView>
</subviews>
<color key="backgroundColor" red="0.87058823529411766" green="0.94509803921568625" blue="0.94509803921568625" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="FXc-cY-lmX" firstAttribute="leading" secondItem="ntQ-jE-XcH" secondAttribute="leading" id="Kld-5z-2Jg"/>
<constraint firstAttribute="bottom" secondItem="FXc-cY-lmX" secondAttribute="bottom" id="TCP-a7-5SI"/>
<constraint firstItem="FXc-cY-lmX" firstAttribute="top" secondItem="ntQ-jE-XcH" secondAttribute="top" id="pOe-7F-02x"/>
<constraint firstAttribute="trailing" secondItem="FXc-cY-lmX" secondAttribute="trailing" id="xgc-JL-j1J"/>
</constraints>
</view>
<prototypes>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="Regatta" id="01f-yF-69S" userLabel="Regatta Cell" customClass="HomeViewRegattaTableViewCell" customModule="SAPTracker" customModuleProvider="target">
@@ -319,11 +334,14 @@
</barButtonItem>
</navigationItem>
<connections>
<outlet property="footerTextView" destination="FXc-cY-lmX" id="DOf-M8-0Mi"/>
<outlet property="footerView" destination="ntQ-jE-XcH" id="yKn-rf-KUB"/>
<outlet property="headerTitleLabel" destination="lc2-1P-oDt" id="ocg-my-9fB"/>
<outlet property="headerView" destination="mhw-sY-eah" id="9fk-BP-QZw"/>
<outlet property="infoCodeLabel" destination="OqX-q3-43s" id="Naw-7q-X8D"/>
<outlet property="noCodeButton" destination="Fp0-61-7he" id="KZ9-6K-G1M"/>
<outlet property="scanCodeButton" destination="Ieu-ch-jeI" id="keL-Mu-e7V"/>
<outlet property="tableView" destination="OXU-ft-TXZ" id="1BA-dy-00A"/>
<outlet property="titleLabel" destination="lc2-1P-oDt" id="BJe-wC-1Xz"/>
<segue destination="plm-Uw-c62" kind="show" identifier="Scan" id="U8l-If-CrF"/>
<segue destination="4Fb-v3-mkB" kind="presentation" identifier="Settings" id="Xxn-jp-xEB"/>
<segue destination="dfN-Ch-vpm" kind="presentation" identifier="About" id="QMa-LQ-D8c"/>
@@ -1520,7 +1538,7 @@
<userDefinedRuntimeAttribute type="boolean" keyPath="layer.masksToBounds" value="YES"/>
</userDefinedRuntimeAttributes>
<connections>
<action selector="eulaButtonTapped:" destination="WMr-pC-C12" eventType="touchUpInside" id="zYu-4g-apZ"/>
<action selector="termsButtonTapped:" destination="WMr-pC-C12" eventType="touchUpInside" id="twA-aL-l2e"/>
</connections>
</button>
</subviews>
@@ -31,10 +31,14 @@ class ScanViewController: UIViewController {
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
layoutPreviewLayer()
layout()
}
// MARK: - Layouts
// MARK: - Layout
private func layout() {
layoutPreviewLayer()
}
private func layoutPreviewLayer() {
guard let previewLayer = scanPreviewLayer else { return }
@@ -147,8 +147,13 @@ class Translation: NSObject {
// MARK: - HomeView
struct HomeView { static let Key = "\(HomeView.self)"
struct TableView { static let Key = "\(HomeView.Key).\(TableView.self)"
struct Title { static let Key = "\(TableView.Key).\(Title.self)"
struct HeaderTitleLabel { static let Key = "\(HomeView.Key).\(HeaderTitleLabel.self)"
struct Text { static let Key = "\(HeaderTitleLabel.Key).\(Text.self)"
static let String = NSLocalizedString(Key, comment: "")
}
}
struct FooterTextView { static let Key = "\(HomeView.Key).\(FooterTextView.self)"
struct Text { static let Key = "\(FooterTextView.Key).\(Text.self)"
static let String = NSLocalizedString(Key, comment: "")
}
}