只需在Swift中使用简单的iOS应用程序,即可在3个选项下显示图像视图和分段控件。我只是试图根据从分段控件中选择的选项来换出图像。到目前为止,我有这个简单的代码:
class ViewController: UIViewController {
var gallery = ["apple", "banana", "coconut"]
@IBOutlet weak var imageView: UIImageView!
@IBAction func changeSegment(sender: AnyObject) {
let segmentedControl = sender as? UISegmentedControl
if let index = segmentedControl?.selectedSegmentIndex {
imageView.image = UIImage(named: gallery[index])
}
}
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.
}
}
我一直遇到一个打印出来的错误"(lldb)"。它看起来像是在一个断点:
let segmentedControl = sender as? UISegmentedControl
不确定原因。非常感谢任何和所有的帮助!
答案 0 :(得分:1)
您的代码旁边有一个断点。我会清理你的文件并运行。