0

このコードは最後のビュー (正しい位置) を表示するだけで、他のビューをペイントするのを忘れているため、このコードに腹を立てています...

// Gets a stack of devices
let volumes = getDevices()
var index = 0
for device in volumes {
    let volume = devicePrototype
    // devicePrototype it's a custom view
    volume?.setName(name: device.name) // setting the label for the name
    volume?.setIcon(icon: device.icon) // setting the image for the icon
    // Setting the position of the view (width = 600, height = 105)
    // and all the views have the same size.
    volume?.layer?.frame = CGRect(x: 0, y: index * 105, width: 600, height: 105)
    // Adding the view to the NSClipView (Here's the problem :P)
    devicesStack.addSubview(volume!)
    index += 1
}

問題を見つけるのを手伝ってくれませんか?

4

1 に答える 1

0

ビュー(デバイス)を1つだけ作成し、ループを介して同じものを変更していると思います。同じdevicePrototypeオブジェクトを繰り返し参照し、プロパティのみを変更しています。それを確認してください。

各反復で新しいオブジェクトを初期化してみてください。

let volume = DevicePrototype()
于 2017-01-06T22:16:13.903 に答える