斯威夫特相當於該目標C爲我工作,但我不能爲我的生命得到它在斯威夫特工作:的訪問的UILabel
- (IBAction)acceptWeight:(UIButton *)sender {
int tempValue = (int) currentWeight;
// current weight comes from a UISegementedController
for (UILabel *labels in self.view.subviews)
{
if (labels.tag == currentWeight)
{
bags[tempValue]++;
labels.text = [NSString stringWithFormat:@"%i",bags[tempValue]];
}
}
totalKilo = totalKilo + (int)currentWeight;
self.totalKilo.text = [NSString stringWithFormat:@"%d",totalKilo];
}
我想一般訪問的一個動態調整UILabels的數量,並更新其內容。
有一個工具,我在這裏ojectivec2swift.net試過,但同時t'was在轉換了大膽的嘗試,它並沒有削減芥末
它給
labels.text = [NSString stringWithFormat:@"%i",bags[tempValue]];
,因爲這相當於:
labels.text = "\(bags[tempValue])"
// compiler warns.. Cannot assign to 'text' in 'labels'
披露:這是基於我在這裏問的一個問題: iPhone - how to select from a collection of UILabels? (並在最後沒有o如果答案對我來說確實如此,那麼我最終會試驗我的方式。爲了完整起見 [按要求]這是在上下文中
@IBAction func acceptWeight(sender: UIButton) {
var tempValue: Int = currentWeight
for labels: UILabel in self.view.subviews {
if labels.tag == currentWeight {
bags[tempValue]++
labels.text = "\(bags[tempValue])"
}
}
totalKilo = totalKilo + currentWeight
self.totalKilo.text = "\(totalKilo)"
}
您發佈的Objective-C代碼沒有幫助,也沒有添加到討論中。如果您想要解決此問題的任何幫助,請嘗試用實際完整的Swift實現替換該代碼。你已經發布了一行Swift和一條錯誤消息。您沒有向我們展示出現錯誤的上下文。你要求我們猜測上下文。 – nhgrif