मुझे "शीर्षक टेक्स्ट" IBInspectable विशेषता काम नहीं कर रहा है। मेरे पास UILabel के साथ एक साधारण रूपरेखा दृश्य है जिसे मैं एक आईबीआईएसपेक्टेबल चर "शीर्षक टेक्स्ट" बना देता हूं। मुझे लगता है कि निरीक्षण योग्य "परत" चर अपेक्षित काम करते हैं, लेकिन मेरा कस्टम "शीर्षक टेक्स्ट" नहीं है जो इस ढांचे का उपयोग करके मुख्य दृश्य को अद्यतन करना है।कोको टच फ्रेमवर्क के साथ IBInspectable काम नहीं कर रहा है? (कोड संलग्न)
मुद्दे हैं:
इंटरफ़ेस बिल्डर titleLabel अपडेट नहीं हो? (यानि डिजाइन समय पर) यानी मैं उम्मीद कर रहा हूं कि ऐसा होना चाहिए, जैसे कि यह "परत" वस्तुओं के लिए काम कर रहा है।
रन टाइम पर शीर्षक लेबल का मान आईबी में निर्धारित मूल्य को नहीं उठा रहा है। ध्यान दें कि जब मैं दौड़ता हूं तो मुझे निम्न आउटपुट मिलता है, यानी मेरा कोड जो इसे उत्पन्न करता है "self.titleLabel" वास्तव में शून्य है ??
कोड सारांश
(ख) gcCustomerView.swift
import UIKit
@IBDesignable
class gcCustomView: UIView {
@IBOutlet weak var titleLabel: UILabel!
@IBInspectable var titleText: String = "Default" {
didSet {
if self.titleLabel != nil {
self.titleLabel.text = titleText
} else {
NSLog("Could not set title text as label.text was nil : was trying to set to \(titleText)")
}
}
}
@IBInspectable var cornerRadius: CGFloat = 0 {
didSet {
layer.cornerRadius = cornerRadius
layer.masksToBounds = cornerRadius > 0
}
}
@IBInspectable var borderWidth: CGFloat = 0 {
didSet {
layer.borderWidth = borderWidth
}
}
@IBInspectable var borderColor: UIColor? {
didSet {
layer.borderColor = borderColor?.cgColor
}
}
override init(frame: CGRect) {
super.init(frame: frame)
commitInit()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
commitInit()
}
// Private
func commitInit() {
if self.subviews.count == 0 {
print("Loading Nib")
//let bundle = Bundle(forClass: self.dynamicType)
let bundle = Bundle(for: type(of: self))
let nib = UINib(nibName: "gcCustomView", bundle: bundle)
let view = nib.instantiate(withOwner: self, options: nil)[0] as! UIView
view.frame = bounds
view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
addSubview(view)
}
}
}
(ग) Main.storyboard स्नैपशॉट
बहुत धन्यवाद - यह उत्तर सबसे अच्छा है जहां मैं गलत हो गया था और दस्तावेजों को सही करने के लिए दस्तावेज किया गया था – Greg