Skip to content

Commit 168b85e

Browse files
committed
No data view added
1 parent 25915d7 commit 168b85e

File tree

9 files changed

+154
-19
lines changed

9 files changed

+154
-19
lines changed

Example/LoadingViewController/ViewController.swift

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,8 @@ class ViewController: LoadingViewController {
1919
delay(1.0) { [weak self] in
2020
self?.setVisibleScreen(.Loading)
2121
self?.delay(3, closure: { [weak self] in
22-
let userInfo = [NSLocalizedDescriptionKey:NSLocalizedString("Operation was unsuccessful.", comment: ""), NSLocalizedFailureReasonErrorKey:NSLocalizedString("The operation timed out.", comment:""), NSLocalizedRecoverySuggestionErrorKey:NSLocalizedString("Have you tried turning it off and on again?", comment: "")]
23-
let error = NSError(domain: "some doman", code: 1000, userInfo: userInfo)
24-
self?.lastError = error
25-
26-
self?.errorIcon = UIImage(named: "doc_fail")
27-
self?.setVisibleScreen(.Failure)
28-
self?.delay(2, closure: {
29-
self?.setVisibleScreen(.Loading)
30-
self?.delay(2, closure: { [weak self] in
31-
self?.setVisibleScreen(.Content)
32-
})
33-
})
22+
self?.noDataMessage = "You don't have any search results. Please, refine your search criteria and try again."
23+
self?.setVisibleScreen(.NoData)
3424
})
3525
}
3626
}

Example/Pods/Pods.xcodeproj/project.pbxproj

Lines changed: 22 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
-402 KB
Binary file not shown.

LoadingViewController/Classes/LoadingViewController.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ public class LoadingViewController: UIViewController {
7373
//MARK:- Default views
7474

7575
func defaultNoDataView() -> UIView {
76-
//TODO: create default view for No Data
77-
return UIView()
76+
let view = NoDataView.viewWithStyle(noDataViewStyle())
77+
view.message = noDataMessage
78+
return view
7879
}
7980

8081
func defaultErrorView() -> UIView {
@@ -100,6 +101,10 @@ public class LoadingViewController: UIViewController {
100101
public func errorViewStyle() -> ErrorViewStyle {
101102
return .Simple
102103
}
104+
105+
public func noDataViewStyle() -> NoDataViewStyle {
106+
return .Simple
107+
}
103108

104109
public func showsErrorView() -> Bool {
105110
return true

LoadingViewController/Classes/Views/ErrorViews/SimpleErrorView.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ class SimpleErrorView: ErrorView {
1818

1919
override func didSetTitle() {
2020
titleLabel?.text = title
21+
layoutIfNeeded()
2122
}
2223

2324
override func didSetMessage() {
2425
messageLabel?.text = message ?? ""
26+
layoutIfNeeded()
2527
}
2628

2729
override func didSetImage() {

LoadingViewController/Classes/Views/ErrorViews/SimpleErrorView.xib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="10117" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
33
<dependencies>
44
<deployment identifier="iOS"/>
55
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//
2+
// NoDataView.swift
3+
// Pods
4+
//
5+
// Created by Sapozhnik Ivan on 13.07.16.
6+
//
7+
//
8+
9+
import UIKit
10+
11+
public enum NoDataViewStyle {
12+
case Simple
13+
}
14+
15+
class NoDataView: UIView {
16+
17+
var title: String? {
18+
didSet {
19+
didSetTitle()
20+
}
21+
}
22+
var message: String? {
23+
didSet {
24+
didSetMessage()
25+
}
26+
}
27+
var image: UIImage? {
28+
didSet {
29+
didSetImage()
30+
}
31+
}
32+
33+
static func viewWithStyle(style: NoDataViewStyle) -> NoDataView {
34+
35+
switch style {
36+
case .Simple:
37+
let errorView = SimpleNoDataView.loadFromNib()
38+
return errorView
39+
}
40+
}
41+
42+
func didSetTitle() {}
43+
func didSetMessage() {}
44+
func didSetImage() {}
45+
func didSetAction() {}
46+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// SimpleNoDataView.swift
3+
// Pods
4+
//
5+
// Created by Sapozhnik Ivan on 13.07.16.
6+
//
7+
//
8+
9+
import UIKit
10+
11+
class SimpleNoDataView: NoDataView {
12+
13+
@IBOutlet weak var imageView: UIImageView!
14+
@IBOutlet var messageLabel: UILabel!
15+
16+
override func didSetMessage() {
17+
messageLabel?.text = message ?? ""
18+
layoutIfNeeded()
19+
}
20+
21+
override func didSetImage() {
22+
guard let newImage = image else { return }
23+
imageView?.image = newImage
24+
}
25+
26+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="10117" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
3+
<dependencies>
4+
<deployment identifier="iOS"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
6+
</dependencies>
7+
<objects>
8+
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
9+
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
10+
<view contentMode="scaleToFill" id="iN0-l3-epB" customClass="SimpleNoDataView" customModule="LoadingViewController" customModuleProvider="target">
11+
<rect key="frame" x="0.0" y="0.0" width="317" height="490"/>
12+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
13+
<subviews>
14+
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="be0-fe-St9">
15+
<rect key="frame" x="50" y="0.0" width="217" height="490"/>
16+
<subviews>
17+
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="You don't have any results yet" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" preferredMaxLayoutWidth="220" translatesAutoresizingMaskIntoConstraints="NO" id="TKv-NH-Fmk">
18+
<rect key="frame" x="0.0" y="160" width="217" height="38.5"/>
19+
<color key="backgroundColor" red="0.40784313729999999" green="0.41568627450000001" blue="0.50980392159999999" alpha="0.0" colorSpace="calibratedRGB"/>
20+
<fontDescription key="fontDescription" name="HelveticaNeue-Bold" family="Helvetica Neue" pointSize="16"/>
21+
<color key="textColor" red="0.40784313729999999" green="0.41568627450000001" blue="0.50980392159999999" alpha="1" colorSpace="calibratedRGB"/>
22+
<nil key="highlightedColor"/>
23+
</label>
24+
</subviews>
25+
<color key="backgroundColor" white="1" alpha="0.0" colorSpace="custom" customColorSpace="calibratedWhite"/>
26+
<constraints>
27+
<constraint firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="TKv-NH-Fmk" secondAttribute="bottom" constant="20" id="29L-7e-kf6"/>
28+
<constraint firstItem="TKv-NH-Fmk" firstAttribute="top" secondItem="be0-fe-St9" secondAttribute="top" constant="160" id="eUe-kz-WmZ"/>
29+
<constraint firstItem="TKv-NH-Fmk" firstAttribute="leading" secondItem="be0-fe-St9" secondAttribute="leading" id="rGn-Du-v8Q"/>
30+
<constraint firstAttribute="trailing" secondItem="TKv-NH-Fmk" secondAttribute="trailing" id="xOD-yQ-FCZ"/>
31+
</constraints>
32+
</view>
33+
</subviews>
34+
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
35+
<constraints>
36+
<constraint firstAttribute="bottom" secondItem="be0-fe-St9" secondAttribute="bottom" id="dVn-P6-I67"/>
37+
<constraint firstAttribute="trailing" secondItem="be0-fe-St9" secondAttribute="trailing" constant="50" id="t5h-0b-YZo"/>
38+
<constraint firstItem="be0-fe-St9" firstAttribute="top" secondItem="iN0-l3-epB" secondAttribute="top" id="yQW-CP-CVp"/>
39+
<constraint firstItem="be0-fe-St9" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="50" id="yez-nk-v47"/>
40+
</constraints>
41+
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
42+
<connections>
43+
<outlet property="messageLabel" destination="TKv-NH-Fmk" id="6Az-0l-es3"/>
44+
</connections>
45+
<point key="canvasLocation" x="69.5" y="265"/>
46+
</view>
47+
</objects>
48+
</document>

0 commit comments

Comments
 (0)