Skip to content

Commit 89736b8

Browse files
committed
fix possible crash
1 parent ec9a55c commit 89736b8

File tree

5 files changed

+16
-4
lines changed

5 files changed

+16
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TBEmptyDataSet.xcworkspace/xcuserdata

Example/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
<key>CFBundlePackageType</key>
1616
<string>APPL</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>2.1</string>
18+
<string>2.2</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>
22-
<string>12</string>
22+
<string>13</string>
2323
<key>LSRequiresIPhoneOS</key>
2424
<true/>
2525
<key>UILaunchStoryboardName</key>

TBEmptyDataSet/EmptyDataView.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,22 @@ internal class EmptyDataView: UIView {
149149
var views = [String: UIView]()
150150

151151
if shouldShowImageView() {
152+
if imageView.superview == nil {
153+
contentView.addSubview(imageView)
154+
}
152155
let viewString = ViewStrings.imageView
153156
viewStrings.append(viewString)
154157
views[viewString] = imageView
155158

156159
contentView.addConstraint(NSLayoutConstraint(item: imageView, attribute: .centerX, relatedBy: .equal, toItem: contentView, attribute: .centerX, multiplier: 1, constant: 0))
160+
} else {
161+
imageView.removeFromSuperview()
157162
}
158163

159164
if shouldShowTitleLabel() {
165+
if titleLabel.superview == nil {
166+
contentView.addSubview(titleLabel)
167+
}
160168
let viewString = ViewStrings.titleLabel
161169
viewStrings.append(viewString)
162170
views[viewString] = titleLabel
@@ -166,6 +174,9 @@ internal class EmptyDataView: UIView {
166174
}
167175

168176
if shouldShowDescriptionLabel() {
177+
if descriptionLabel.superview == nil {
178+
contentView.addSubview(descriptionLabel)
179+
}
169180
let viewString = ViewStrings.descriptionLabel
170181
viewStrings.append(viewString)
171182
views[viewString] = descriptionLabel

TBEmptyDataSet/Supporting Files/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>2.1</string>
18+
<string>2.2</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

TBEmptyDataSetExample.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@
166166
);
167167
runOnlyForDeploymentPostprocessing = 0;
168168
shellPath = /bin/sh;
169-
shellScript = swiftlint;
169+
shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi";
170170
};
171171
/* End PBXShellScriptBuildPhase section */
172172

0 commit comments

Comments
 (0)