无法使用类型为“()”的索引为类型为“[UIImage]”的值下标
Cannot subscript a value of type '[UIImage]' with an index of type '()'
我一直收到这个错误:
cannot subscript a value of type '[UIImage]' with an index of type '()'
这是我的代码:
let images: [UIImage] = [
UIImage(named: "profilePicture.jpg")!,
UIImage(named: "back3.jpg")!,
UIImage(named: "back1.jpg")!]
var index = 0
let animationDuration: TimeInterval = 0.25
let switchingInterval: TimeInterval = 3
let chnagingImageView = UIImageView()
override func viewDidLoad() {
chnagingImageView.frame = CGRect(x: 0, y: 300, width: view.frame.width, height: 200)
view.addSubview(chnagingImageView)
chnagingImageView.image = images[index += 1]
animateImageView()
}
错误发生在这一行:
chnagingImageView.image = images[index += 1]
如有任何帮助,我们将不胜感激。请注意,我看到另一个问题,这只是游乐场的问题,它提供的解决方案只是刷新代码。但是,这不起作用,我仍然收到错误消息。
改为
index += 1
chnagingImageView.image = images[index]
因为index += 1
return ()
=> 数组无法获取索引类型为()
的值
let images: [UIImage] = [
UIImage(named: "profilePicture.jpg")!,
UIImage(named: "back3.jpg")!,
UIImage(named: "back1.jpg")!]
var index = 0
let animationDuration: TimeInterval = 0.25
let switchingInterval: TimeInterval = 3
let chnagingImageView = UIImageView()
override func viewDidLoad() {
chnagingImageView.frame = CGRect(x: 0, y: 300, width: view.frame.width, height: 200)
view.addSubview(chnagingImageView)
for myimage in images.count-1
{
if myimage==1
{
chnagingImageView.image = images[myimage]
}
}
}
我一直收到这个错误:
cannot subscript a value of type '[UIImage]' with an index of type '()'
这是我的代码:
let images: [UIImage] = [
UIImage(named: "profilePicture.jpg")!,
UIImage(named: "back3.jpg")!,
UIImage(named: "back1.jpg")!]
var index = 0
let animationDuration: TimeInterval = 0.25
let switchingInterval: TimeInterval = 3
let chnagingImageView = UIImageView()
override func viewDidLoad() {
chnagingImageView.frame = CGRect(x: 0, y: 300, width: view.frame.width, height: 200)
view.addSubview(chnagingImageView)
chnagingImageView.image = images[index += 1]
animateImageView()
}
错误发生在这一行:
chnagingImageView.image = images[index += 1]
如有任何帮助,我们将不胜感激。请注意,我看到另一个问题,这只是游乐场的问题,它提供的解决方案只是刷新代码。但是,这不起作用,我仍然收到错误消息。
改为
index += 1
chnagingImageView.image = images[index]
因为index += 1
return ()
=> 数组无法获取索引类型为()
let images: [UIImage] = [
UIImage(named: "profilePicture.jpg")!,
UIImage(named: "back3.jpg")!,
UIImage(named: "back1.jpg")!]
var index = 0
let animationDuration: TimeInterval = 0.25
let switchingInterval: TimeInterval = 3
let chnagingImageView = UIImageView()
override func viewDidLoad() {
chnagingImageView.frame = CGRect(x: 0, y: 300, width: view.frame.width, height: 200)
view.addSubview(chnagingImageView)
for myimage in images.count-1
{
if myimage==1
{
chnagingImageView.image = images[myimage]
}
}
}