我在UIView
类中有全局初始化变量。全局初始化变量在Swift UIView XIB中更改为'nil'?
变量是statusLabel
作为字符串。我在Pickerview didSelectRow
委托方法中为statusLabel
分配了一个值。 在那里我得到了字符串的值。但是,代表完成字符串更改的值时nil
所有其他全局初始化变量都一样。 可能是什么原因?
由于提前
class CustomPickerMenu: UIView,UIPickerViewDataSource,UIPickerViewDelegate
{
var statusLabel = String()
var pickerArray = [String]()
required init?(coder aDecoder: NSCoder)
{
pickerArray = ["None","Connections","All"]
super.init(coder: aDecoder)
print("Awake with coder")
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
{
if(row == 0)
{
statusLabel = pickerArray[row]
}
if(row == 1)
{
statusLabel = pickerArray[row]
}
if(row == 2)
{
statusLabel = pickerArray[row]
}
print("statusLabel : " + statusLabel)
}
@IBAction func saveStatus(_ sender: Any)
{
delegate?.statusChange(controller: self, text:statusLabel)
self.delegate?.showNavigationController(controller: self)
print("statusLabel : " + statusLabel)
}
这里是didselectrow代表(第1三路输出)在输出statusLabel和保存状态(最后输出)
把问题的实际代码代替图像 – Rajat
1.作为@Rajat在上面的评论中提到,添加代码不是图像。 2.在实际尝试访问变量的地方添加代码,并将其找到为空。 – lukya
这里是完整的代码 – fAiSaL