gpt4 book ai didi

ios - 创建一组图像并在 Apple Watch 上随机显示一个

转载 作者:搜寻专家 更新时间:2023-11-01 07:11:00 25 4
gpt4 key购买 nike

我正在尝试为 Apple Watch 添加我的第一个扩展程序,但在为应用程序创建数组时遇到问题。当我运行该应用程序时,它崩溃了,我的数组中显示了这个错误:

Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

下面是我的代码,我只想在每次点击按钮时将我的图像更改为数组中的随机图像:

import WatchKit
import Foundation

class InterfaceController: WKInterfaceController {

let runeArray = [UIImage(named: ("Fehu.png"))!, UIImage(named: ("Uruz.png"))!, UIImage(named: ("Thurisaz.png"))!]

@IBOutlet var runeImage: WKInterfaceImage!

override func awake(withContext context: Any?) {
super.awake(withContext: context)

// Configure interface objects here.
}

override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
}

override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}

@IBAction func castRuneButton() {

let randomRune = runeArray[Int(arc4random_uniform(UInt32(runeArray.count)))]
runeImage.setImage(randomRune)
}
}

enter image description here

最佳答案

确保您已为 Assets 目录选择了 iOS 和 watch 扩展目标。

关于ios - 创建一组图像并在 Apple Watch 上随机显示一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44920940/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com