我担心的问题。我有一个按钮和一个标签。
@IBOutlet weak var addProductDetails: UIButton!
@IBOutlet weak var countProductDetails: UILabel!
我能够单击该按钮,然后在此之后我尝试更新UILabel的值。但是价值没有更新。
@IBAction func plusIconClicked1(_ sender: UIButton) {
var q = Int(self.countProductDetails.text!)!
q = q + 1;
if(q >= 0) {
if(q>10) {
AFWrapper.showError("", msg: "Sorry, You can't add more of these items")
} else {
print("plusIconClicked1")
print("Value of Q is : \(q)")
print("countProductDetails 1 ", countProductDetails)
self.countProductDetails.text = "\(q)"
print("countProductDetails 2 ", countProductDetails)
}
}
}
第一次单击按钮,日志为:
plusIconClicked1
Value of Q is : 1
countProductDetails 1 some(<UILabel: 0x7f862083bac0; frame = (238.5 90; 30.5 28); text = '0'; opaque = NO; autoresize = LM+W+BM; layer = <_UILabelLayer: 0x7f861e688930>>)
countProductDetails 2 some(<UILabel: 0x7f862083bac0; frame = (238.5 90; 30.5 28); text = '1'; opaque = NO; autoresize = LM+W+BM; layer = <_UILabelLayer: 0x7f861e688930>>)
第二次单击按钮,日志为:
plusIconClicked1
Value of Q is : 2
countProductDetails 1 some(<UILabel: 0x7f862083bac0; frame = (238.5 90; 30.5 28); text = '1'; opaque = NO; autoresize = LM+W+BM; layer = <_UILabelLayer: 0x7f861e688930>>)
countProductDetails 2 some(<UILabel: 0x7f862083bac0; frame = (238.5 90; 30.5 28); text = '2'; opaque = NO; autoresize = LM+W+BM; layer = <_UILabelLayer: 0x7f861e688930>>)
答案 0 :(得分:0)
只需将String(q)更改为
"\(q)"
检查q中是否有值。
答案 1 :(得分:0)
通过查看您的代码 self.countProductDetails.text 仅在(q> = 0)&&(q <= 10)时更改。
您可以在
之前打印q的值 if(q >= 0) {
喜欢
print("Value of Q is : \(q)")
并检查 q
的值是什么我认为语法没有问题。请提及您要达到的目标。