0
我想在Swift中xCode 6中按下按钮时将图像更改为另一图像。我有我已经声明为一个IBOutlet,并尝试使用该命令的形象图:如何更改ImageView的图像?
myImageView.image = [UIImage imageNamed:@"image2.png]
但我得到该行的代码如下错误:
- 上连续发言行必须用';'隔开
- 预期Decleration
- 在容器字面预期表达
- 在容器文字表达
- 预期属性名称
这里是低于我的代码预期 ']':
import UIKit
import AVFoundation
class ViewController: UIViewController {
@IBOutlet weak var photoImageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func Play(sender: AnyObject) {
photoImageView.image = [UIImage imageNamed:@"litup.jpeg"]
}
}
我试图您提供的解决方案。我不再在ViewController.swift中得到错误,但是当我按下按钮时,应用程序仍然崩溃。当我删除行应用程序工作正常。 Identity Inspector或Attributes Inspector中的设置是否可能干扰该代码行? –
你能告诉我更多关于坠机事件吗?当应用程序崩溃时,你看到什么错误? – Moriya
几分钟前刚刚尝试过,它似乎工作正常。抱歉打扰你,并感谢你的帮助。 –