Skip to content

Commit 892e502

Browse files
committed
Added explanation for updating the view from the view controller
1 parent e1677d8 commit 892e502

File tree

4 files changed

+30
-15
lines changed

4 files changed

+30
-15
lines changed

.DS_Store

0 Bytes
Binary file not shown.

MSAutoView/Base.lproj/Main.storyboard

+3-7
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,14 @@
2222
<rect key="frame" x="67" y="238" width="240" height="128"/>
2323
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
2424
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
25-
<userDefinedRuntimeAttributes>
26-
<userDefinedRuntimeAttribute type="string" keyPath="title" value="This is an overriden title"/>
27-
<userDefinedRuntimeAttribute type="number" keyPath="price">
28-
<real key="value" value="2"/>
29-
</userDefinedRuntimeAttribute>
30-
<userDefinedRuntimeAttribute type="string" keyPath="details" value="This is an overriden details"/>
31-
</userDefinedRuntimeAttributes>
3225
</view>
3326
</subviews>
3427
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
3528
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
3629
</view>
30+
<connections>
31+
<outlet property="listingView" destination="XKD-5Y-F7e" id="iTX-g0-re5"/>
32+
</connections>
3733
</viewController>
3834
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
3935
</objects>

MSAutoView/ViewController.swift

+6-7
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,15 @@ import UIKit
2626

2727
class ViewController: UIViewController {
2828

29+
@IBOutlet weak var listingView: ListingView!
30+
2931
override func viewDidLoad() {
3032
super.viewDidLoad()
31-
// Do any additional setup after loading the view, typically from a nib.
33+
listingView.title = "Title from View Controller"
34+
listingView.details = "Details from View Controller"
35+
listingView.price = 40
36+
listingView.updateView()
3237
}
3338

34-
override func didReceiveMemoryWarning() {
35-
super.didReceiveMemoryWarning()
36-
// Dispose of any resources that can be recreated.
37-
}
38-
39-
4039
}
4140

README.md

+21-1
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,34 @@ class ListingView: MSAutoView {
9292

9393
![Image](https://user-images.githubusercontent.com/24646608/34811485-34100180-f6f5-11e7-9671-44705690d06b.png)
9494

95-
- You can also override the default values from the storyboard's attributes inspector for the view:
95+
- You can also override the default values from the storyboard's attributes inspector for the view (**Make sure you don't set the attributes in the attribute inspector of the xib or they will override all other values**):
9696

9797
![Image](https://user-images.githubusercontent.com/24646608/34811582-a519fe26-f6f5-11e7-8d71-80bb77d8c55f.png)
9898

9999
This is the result:
100100

101101
![Image](https://user-images.githubusercontent.com/24646608/34811599-c514e92a-f6f5-11e7-9405-e85e7ced94d5.png)
102102

103+
- You can also create a reference for the view in the view controller's class and set its values:
104+
105+
```swift
106+
class ViewController: UIViewController {
107+
108+
@IBOutlet weak var listingView: ListingView!
109+
110+
override func viewDidLoad() {
111+
super.viewDidLoad()
112+
listingView.title = "Title from View Controller"
113+
listingView.details = "Details from View Controller"
114+
listingView.price = 40
115+
listingView.updateView()
116+
}
117+
118+
}
119+
```
120+
121+
![Image](https://user-images.githubusercontent.com/24646608/34811911-7f51df36-f6f7-11e7-9a48-fce96c59d195.png)
122+
103123
## Deployment
104124

105125
If you want to use the auto view in your own project just copy the AutoView Folder.

0 commit comments

Comments
 (0)