Skip to content

Commit 0a91426

Browse files
Reorganize views in xibs to avoid Interface Builder error that sometimes it cannot load child xib into parent xib
1 parent 7998ebe commit 0a91426

13 files changed

Lines changed: 142 additions & 143 deletions

iOS-application/BLEServo/BLEServo/ViewsAndViewModels/Controls/AxisView.swift

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,15 @@ import UIKit
99

1010
@IBDesignable
1111
class AxisView: UIViewWithNib {
12-
@IBOutlet weak var backgroundView: UIView!
13-
@IBOutlet weak var labelName: UILabel!
14-
@IBOutlet weak var labelValue: UILabel!
15-
@IBOutlet weak var slider: UISlider!
16-
@IBOutlet weak var constraintLabelToView: NSLayoutConstraint!
17-
12+
var content: AxisContentView { contentView as! AxisContentView }
1813
var viewModel: AxisViewModel? { didSet { connectToViewModel() } }
1914

2015
override var intrinsicContentSize: CGSize {
21-
CGSize(width: bounds.width, height: backgroundView.bounds.height + labelName.bounds.height + constraintLabelToView.constant)
16+
CGSize(width: bounds.width, height: content.backgroundView.bounds.height + content.labelName.bounds.height + content.constraintLabelToView.constant)
2217
}
2318

2419
@IBAction func onSliderDidChange(_ sender: Any) {
25-
viewModel?.value = slider.value
20+
viewModel?.value = content.slider.value
2621
}
2722

2823
@IBAction func onSliderTouchUp(_ sender: Any) {
@@ -34,17 +29,25 @@ class AxisView: UIViewWithNib {
3429
private extension AxisView {
3530
private func connectToViewModel() {
3631
guard let viewModel = viewModel else {
37-
labelValue.text = "disconnected"
32+
content.labelValue.text = "disconnected"
3833
return
3934
}
40-
labelName.text = viewModel.axisName
41-
labelValue.text = viewModel.displayValue
35+
content.labelName.text = viewModel.axisName
36+
content.labelValue.text = viewModel.displayValue
4237
viewModel.onDisplayValueDidChange = { [weak self] (displayValue: String) in
43-
self?.labelValue.text = viewModel.displayValue
38+
self?.content.labelValue.text = viewModel.displayValue
4439
}
45-
slider.value = viewModel.value
40+
content.slider.value = viewModel.value
4641
viewModel.onValueDidChange = { [weak self] (value: Float) in
47-
self?.slider.value = value
42+
self?.content.slider.value = value
4843
}
4944
}
5045
}
46+
47+
class AxisContentView: UIView {
48+
@IBOutlet weak var backgroundView: UIView!
49+
@IBOutlet weak var labelName: UILabel!
50+
@IBOutlet weak var labelValue: UILabel!
51+
@IBOutlet weak var slider: UISlider!
52+
@IBOutlet weak var constraintLabelToView: NSLayoutConstraint!
53+
}

iOS-application/BLEServo/BLEServo/ViewsAndViewModels/Controls/AxisView.xib

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,9 @@
99
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
1010
</dependencies>
1111
<objects>
12-
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="AxisView" customModule="BLEServo" customModuleProvider="target">
13-
<connections>
14-
<outlet property="backgroundView" destination="DKg-CZ-bpc" id="UJN-FI-DqS"/>
15-
<outlet property="constraintLabelToView" destination="0cc-FQ-IHe" id="k8L-YG-GHN"/>
16-
<outlet property="labelName" destination="fH1-cK-Tmj" id="OQ6-Se-wBa"/>
17-
<outlet property="labelValue" destination="SFp-Lw-wMD" id="JZi-0u-WcG"/>
18-
<outlet property="slider" destination="Kak-h5-xvI" id="1GJ-Ng-eOk"/>
19-
</connections>
20-
</placeholder>
12+
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="AxisView" customModule="BLEServo" customModuleProvider="target"/>
2113
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
22-
<view contentMode="scaleToFill" id="iN0-l3-epB">
14+
<view contentMode="scaleToFill" id="iN0-l3-epB" customClass="AxisContentView" customModule="BLEServo" customModuleProvider="target">
2315
<rect key="frame" x="0.0" y="0.0" width="394" height="160"/>
2416
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
2517
<subviews>
@@ -40,7 +32,7 @@
4032
<nil key="highlightedColor"/>
4133
</label>
4234
</subviews>
43-
<color key="backgroundColor" systemColor="tertiarySystemBackgroundColor"/>
35+
<color key="backgroundColor" systemColor="secondarySystemGroupedBackgroundColor"/>
4436
<constraints>
4537
<constraint firstItem="Kak-h5-xvI" firstAttribute="top" secondItem="SFp-Lw-wMD" secondAttribute="bottom" constant="8" id="3uC-nv-0be"/>
4638
<constraint firstAttribute="trailing" secondItem="Kak-h5-xvI" secondAttribute="trailing" constant="10" id="CKZ-JC-O9Q"/>
@@ -74,14 +66,21 @@
7466
<constraint firstItem="vUN-kp-3ea" firstAttribute="top" secondItem="fH1-cK-Tmj" secondAttribute="top" id="hKo-xM-Ru3"/>
7567
</constraints>
7668
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
69+
<connections>
70+
<outlet property="backgroundView" destination="DKg-CZ-bpc" id="Jml-2m-mTA"/>
71+
<outlet property="constraintLabelToView" destination="0cc-FQ-IHe" id="TIO-8X-VPX"/>
72+
<outlet property="labelName" destination="fH1-cK-Tmj" id="FjH-06-HES"/>
73+
<outlet property="labelValue" destination="SFp-Lw-wMD" id="01W-fx-2zt"/>
74+
<outlet property="slider" destination="Kak-h5-xvI" id="SG4-5H-oZX"/>
75+
</connections>
7776
<point key="canvasLocation" x="117.39130434782609" y="-146.65178571428569"/>
7877
</view>
7978
</objects>
8079
<resources>
8180
<systemColor name="secondaryLabelColor">
8281
<color red="0.23529411764705882" green="0.23529411764705882" blue="0.2627450980392157" alpha="0.59999999999999998" colorSpace="custom" customColorSpace="sRGB"/>
8382
</systemColor>
84-
<systemColor name="tertiarySystemBackgroundColor">
83+
<systemColor name="secondarySystemGroupedBackgroundColor">
8584
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
8685
</systemColor>
8786
</resources>

iOS-application/BLEServo/BLEServo/ViewsAndViewModels/Controls/ButtonsHAxisView.swift

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@ import UIKit
99

1010
@IBDesignable
1111
class ButtonsHAxisView: UIViewWithNib {
12-
@IBOutlet weak var stackViewButtons: UIStackView!
13-
@IBOutlet weak var axisValueView: AxisRenderValueView!
14-
12+
var content: ButtonsHAxisContentView { contentView as! ButtonsHAxisContentView }
1513
var viewModel: ButtonsAxisViewModel? { didSet { connectToViewModel() } }
1614

1715
override var intrinsicContentSize: CGSize {
18-
stackViewButtons.intrinsicContentSize
16+
content.stackViewButtons.intrinsicContentSize
1917
}
2018

2119
@IBAction func onButtonLeftPress(_ sender: Any) {
@@ -38,12 +36,17 @@ class ButtonsHAxisView: UIViewWithNib {
3836
private extension ButtonsHAxisView {
3937
func connectToViewModel() {
4038
guard let viewModel = viewModel else {
41-
axisValueView.axisValue = 0
39+
content.axisValueView.axisValue = 0
4240
return
4341
}
4442
viewModel.onValueDidChange = { [weak self] (newValue) in
45-
self?.axisValueView.axisValue = newValue
43+
self?.content.axisValueView.axisValue = newValue
4644
}
47-
axisValueView.axisValue = viewModel.value
45+
content.axisValueView.axisValue = viewModel.value
4846
}
4947
}
48+
49+
class ButtonsHAxisContentView: UIView {
50+
@IBOutlet weak var stackViewButtons: UIStackView!
51+
@IBOutlet weak var axisValueView: AxisRenderValueView!
52+
}

iOS-application/BLEServo/BLEServo/ViewsAndViewModels/Controls/ButtonsHAxisView.xib

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,9 @@
88
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
99
</dependencies>
1010
<objects>
11-
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="ButtonsHAxisView" customModule="BLEServo" customModuleProvider="target">
12-
<connections>
13-
<outlet property="axisValueView" destination="ydi-a6-YGr" id="PQ7-DK-Vtm"/>
14-
<outlet property="stackViewButtons" destination="L0S-lH-S15" id="Z9C-Z1-tbL"/>
15-
</connections>
16-
</placeholder>
11+
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="ButtonsHAxisView" customModule="BLEServo" customModuleProvider="target"/>
1712
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
18-
<view contentMode="scaleToFill" id="iN0-l3-epB">
13+
<view contentMode="scaleToFill" id="iN0-l3-epB" customClass="ButtonsHAxisContentView" customModule="BLEServo" customModuleProvider="target">
1914
<rect key="frame" x="0.0" y="0.0" width="307" height="226"/>
2015
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
2116
<subviews>
@@ -69,6 +64,10 @@
6964
<constraint firstItem="L0S-lH-S15" firstAttribute="centerY" secondItem="vUN-kp-3ea" secondAttribute="centerY" id="kth-Ce-Zb4"/>
7065
</constraints>
7166
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
67+
<connections>
68+
<outlet property="axisValueView" destination="ydi-a6-YGr" id="6Ay-eW-YVM"/>
69+
<outlet property="stackViewButtons" destination="L0S-lH-S15" id="X5h-oJ-zg1"/>
70+
</connections>
7271
<point key="canvasLocation" x="41.304347826086961" y="-143.30357142857142"/>
7372
</view>
7473
</objects>

iOS-application/BLEServo/BLEServo/ViewsAndViewModels/Controls/ButtonsVAxisView.swift

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@ import UIKit
99

1010
@IBDesignable
1111
class ButtonsVAxisView: UIViewWithNib {
12-
@IBOutlet weak var stackViewButtons: UIStackView!
13-
@IBOutlet weak var axisValueView: AxisRenderValueView!
14-
12+
var content: ButtonsVAxisContentView { contentView as! ButtonsVAxisContentView }
1513
var viewModel: ButtonsAxisViewModel? { didSet { connectToViewModel() } }
1614

1715
override var intrinsicContentSize: CGSize {
18-
stackViewButtons.intrinsicContentSize
16+
content.stackViewButtons.intrinsicContentSize
1917
}
2018

2119
@IBAction func onButtonUpPress(_ sender: Any) {
@@ -38,12 +36,17 @@ class ButtonsVAxisView: UIViewWithNib {
3836
private extension ButtonsVAxisView {
3937
func connectToViewModel() {
4038
guard let viewModel = viewModel else {
41-
axisValueView.axisValue = 0
39+
content.axisValueView.axisValue = 0
4240
return
4341
}
4442
viewModel.onValueDidChange = { [weak self] (newValue) in
45-
self?.axisValueView.axisValue = newValue
43+
self?.content.axisValueView.axisValue = newValue
4644
}
47-
axisValueView.axisValue = viewModel.value
45+
content.axisValueView.axisValue = viewModel.value
4846
}
4947
}
48+
49+
class ButtonsVAxisContentView: UIView {
50+
@IBOutlet weak var stackViewButtons: UIStackView!
51+
@IBOutlet weak var axisValueView: AxisRenderValueView!
52+
}

iOS-application/BLEServo/BLEServo/ViewsAndViewModels/Controls/ButtonsVAxisView.xib

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,9 @@
88
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
99
</dependencies>
1010
<objects>
11-
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="ButtonsVAxisView" customModule="BLEServo" customModuleProvider="target">
12-
<connections>
13-
<outlet property="axisValueView" destination="WFc-iN-SBF" id="Fy7-SA-8bc"/>
14-
<outlet property="stackViewButtons" destination="mxM-qM-uEB" id="mJi-2T-ohm"/>
15-
</connections>
16-
</placeholder>
11+
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="ButtonsVAxisView" customModule="BLEServo" customModuleProvider="target"/>
1712
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
18-
<view contentMode="scaleToFill" id="iN0-l3-epB">
13+
<view contentMode="scaleToFill" id="iN0-l3-epB" customClass="ButtonsVAxisContentView" customModule="BLEServo" customModuleProvider="target">
1914
<rect key="frame" x="0.0" y="0.0" width="257" height="386"/>
2015
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
2116
<subviews>
@@ -71,6 +66,10 @@
7166
<nil key="simulatedTopBarMetrics"/>
7267
<nil key="simulatedBottomBarMetrics"/>
7368
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
69+
<connections>
70+
<outlet property="axisValueView" destination="WFc-iN-SBF" id="L1U-1o-OHH"/>
71+
<outlet property="stackViewButtons" destination="mxM-qM-uEB" id="Ljg-Ss-RE6"/>
72+
</connections>
7473
<point key="canvasLocation" x="-68.840579710144937" y="-96.428571428571431"/>
7574
</view>
7675
</objects>

iOS-application/BLEServo/BLEServo/ViewsAndViewModels/Controls/ChannelSettingsView.swift

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,11 @@
77

88
import UIKit
99

10+
@IBDesignable
1011
class ChannelSettingsView: UIViewWithNib {
11-
@IBOutlet weak var textFieldMappingNegative: NumericTextField!
12-
@IBOutlet weak var textFieldMappingCenter: NumericTextField!
13-
@IBOutlet weak var textFieldMappingPositive: NumericTextField!
14-
@IBOutlet weak var textFieldChannelIndex: NumericTextField!
15-
@IBOutlet weak var textFieldAnimationSpeed: NumericTextField!
16-
17-
var currentTextField: UITextField?
12+
var content: ChannelSettingsContentView { contentView as! ChannelSettingsContentView }
1813
var viewModel: ChannelSettingsViewModel? { didSet { connectToViewModel() } }
14+
var currentTextField: UITextField?
1915

2016
@IBAction func onTextFieldDidEndOnExit(_ sender: UITextField) {
2117
sender.resignFirstResponder()
@@ -58,10 +54,18 @@ private extension ChannelSettingsView {
5854

5955
func connectToViewModel() {
6056
guard let vm = viewModel else { return }
61-
textFieldMappingNegative.text = vm.updateMappingNegative(wantedValue: nil)
62-
textFieldMappingCenter.text = vm.updateMappingCenter(wantedValue: nil)
63-
textFieldMappingPositive.text = vm.updateMappingPositive(wantedValue: nil)
64-
textFieldChannelIndex.text = vm.updateChannelIndex(wantedValue: nil)
65-
textFieldAnimationSpeed.text = vm.updateAnimationSpeed(wantedValue: nil)
57+
content.textFieldMappingNegative.text = vm.updateMappingNegative(wantedValue: nil)
58+
content.textFieldMappingCenter.text = vm.updateMappingCenter(wantedValue: nil)
59+
content.textFieldMappingPositive.text = vm.updateMappingPositive(wantedValue: nil)
60+
content.textFieldChannelIndex.text = vm.updateChannelIndex(wantedValue: nil)
61+
content.textFieldAnimationSpeed.text = vm.updateAnimationSpeed(wantedValue: nil)
6662
}
6763
}
64+
65+
class ChannelSettingsContentView: UIView {
66+
@IBOutlet weak var textFieldMappingNegative: NumericTextField!
67+
@IBOutlet weak var textFieldMappingCenter: NumericTextField!
68+
@IBOutlet weak var textFieldMappingPositive: NumericTextField!
69+
@IBOutlet weak var textFieldChannelIndex: NumericTextField!
70+
@IBOutlet weak var textFieldAnimationSpeed: NumericTextField!
71+
}

iOS-application/BLEServo/BLEServo/ViewsAndViewModels/Controls/ChannelSettingsView.xib

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,9 @@
99
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
1010
</dependencies>
1111
<objects>
12-
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="ChannelSettingsView" customModule="BLEServo" customModuleProvider="target">
13-
<connections>
14-
<outlet property="textFieldAnimationSpeed" destination="IA0-KS-AhF" id="U8b-33-Plo"/>
15-
<outlet property="textFieldChannelIndex" destination="n0U-9o-zTI" id="ZFj-GS-aFi"/>
16-
<outlet property="textFieldMappingCenter" destination="AQc-VU-wZE" id="kMr-TH-W28"/>
17-
<outlet property="textFieldMappingNegative" destination="5gV-U6-lWa" id="n37-bG-Erc"/>
18-
<outlet property="textFieldMappingPositive" destination="7mn-De-Jqc" id="bMm-Wu-Cks"/>
19-
</connections>
20-
</placeholder>
12+
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="ChannelSettingsView" customModule="BLEServo" customModuleProvider="target"/>
2113
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
22-
<view contentMode="scaleToFill" id="iN0-l3-epB">
14+
<view contentMode="scaleToFill" id="iN0-l3-epB" customClass="ChannelSettingsContentView" customModule="BLEServo" customModuleProvider="target">
2315
<rect key="frame" x="0.0" y="0.0" width="417" height="360"/>
2416
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
2517
<subviews>
@@ -149,7 +141,7 @@
149141
<nil key="highlightedColor"/>
150142
</label>
151143
</subviews>
152-
<color key="backgroundColor" systemColor="tertiarySystemBackgroundColor"/>
144+
<color key="backgroundColor" systemColor="secondarySystemGroupedBackgroundColor"/>
153145
<constraints>
154146
<constraint firstItem="Nlo-F1-6V1" firstAttribute="top" secondItem="rXF-mC-fhD" secondAttribute="bottom" constant="20" id="2Rd-HN-oYf"/>
155147
<constraint firstItem="IA0-KS-AhF" firstAttribute="leading" secondItem="Nlo-F1-6V1" secondAttribute="trailing" constant="20" id="EhO-gL-fAt"/>
@@ -188,14 +180,21 @@
188180
<constraint firstItem="vUN-kp-3ea" firstAttribute="trailing" secondItem="9WG-PR-jku" secondAttribute="trailing" id="y83-9V-7bE"/>
189181
</constraints>
190182
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
183+
<connections>
184+
<outlet property="textFieldAnimationSpeed" destination="IA0-KS-AhF" id="WQc-JJ-LMx"/>
185+
<outlet property="textFieldChannelIndex" destination="n0U-9o-zTI" id="j02-gv-V0u"/>
186+
<outlet property="textFieldMappingCenter" destination="AQc-VU-wZE" id="qmc-Uf-I6M"/>
187+
<outlet property="textFieldMappingNegative" destination="5gV-U6-lWa" id="dsN-45-Ho7"/>
188+
<outlet property="textFieldMappingPositive" destination="7mn-De-Jqc" id="RYu-oI-n2f"/>
189+
</connections>
191190
<point key="canvasLocation" x="134.05797101449275" y="-93.75"/>
192191
</view>
193192
</objects>
194193
<resources>
195194
<systemColor name="secondaryLabelColor">
196195
<color red="0.23529411764705882" green="0.23529411764705882" blue="0.2627450980392157" alpha="0.59999999999999998" colorSpace="custom" customColorSpace="sRGB"/>
197196
</systemColor>
198-
<systemColor name="tertiarySystemBackgroundColor">
197+
<systemColor name="secondarySystemGroupedBackgroundColor">
199198
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
200199
</systemColor>
201200
</resources>

0 commit comments

Comments
 (0)