Ich bin wirklich neu in XCode (swift), und ich versuche, eine UIImageView zufällig eines von drei Bildern zu zeigen, aber wenn ich zum zweiten ViewController im Simulator wechseln Es passiert nichts und XCode hebt das Ende der ViewDidLoad-Funktion hervor, die Thread 1: Haltepunkt 1.1 sagt.Ändern des Bildes in UIImageView, andere XCode-Probleme
Wenn es eine bessere oder zuverlässigere Möglichkeit gibt, UIImageView Bilder zu wechseln, würde ich es gerne wissen.
Mein aktueller Code:
import UIKit
let imageInitialIdentity = arc4random_uniform(3)
class SecondViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
if(imageInitialIdentity == 0){
imageGuess.image = UIImage(named: "0ps.pngs")
imageGuess.frame = CGRect(x: 51, y: 47, width: 500, height: 340)
}
if(imageInitialIdentity == 1){
imageGuess.image = UIImage(named: "250ps.png")
imageGuess.frame = CGRect(x: 51, y: 47, width: 500, height: 340)
}
if(imageInitialIdentity == 2){
imageGuess.image = UIImage(named: "500ps.png")
imageGuess.frame = CGRect(x: 51, y: 47, width: 500, height: 340)
}
// 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.
}
@IBOutlet weak var imageGuess: UIImageView!
var imageIdentity = imageInitialIdentity
var score = 0
let imageZero = UIImage.init(named: "0ps")
let image250 = UIImage.init(named: "250ps")
let image500 = UIImage.init(named: "500ps")
@IBAction func guessZero(sender: UIButton) {
//if zero matches the picture 0, add a point
if imageIdentity == 0{
score++
}
else{
//print incorrect, corect answer is 0
}
//randomizes another picture
let rand1 = arc4random_uniform(3)
if rand1 == 0 {
imageGuess.image = UIImage(named: "0ps.png")
imageGuess.frame = CGRect(x: 51, y: 47, width: 500, height: 340)
imageIdentity = 0
}
else if rand1 == 1{
imageGuess.image = UIImage(named:"250ps.png")
imageGuess.frame = CGRect(x: 51, y: 47, width: 500, height: 340)
imageIdentity = 1
}
else if rand1 == 2{
imageGuess.image = UIImage(named:"500ps.png")
imageGuess.frame = CGRect(x: 51, y: 47, width: 500, height: 340)
imageIdentity = 2
}
}
@IBAction func guess250(sender: UIButton) {
// if 150 matches the picture of 250, return true
//randomizes another picture
//adds one to score?
if imageIdentity == 1{
score++
}
let rand2 = arc4random_uniform(3)
if rand2 == 0 {
imageGuess.image = UIImage(named:"0ps.png")
imageGuess.frame = CGRect(x: 51, y: 47, width: 500, height: 340)
imageIdentity = 0
}
else if rand2 == 1{
imageGuess.image = UIImage(named:"250ps.png")
imageGuess.frame = CGRect(x: 51, y: 47, width: 500, height: 340)
imageIdentity = 1
}
else if rand2 == 2{
imageGuess.image = UIImage(named:"500ps.png")
imageGuess.frame = CGRect(x: 51, y: 47, width: 500, height: 340)
imageIdentity = 2
}
}
@IBAction func guess500(sender: UIButton) {
//if 500 matches the picture of 500, return true
//randomizes another picture
if imageIdentity == 2{
score++
}
let rand3 = arc4random_uniform(3)
if rand3 == 0 {
imageGuess.image = UIImage(named:"0ps.png")
imageGuess.frame = CGRect(x: 51, y: 47, width: 500, height: 340)
imageIdentity = 0
}
else if rand3 == 1{
imageGuess.image = UIImage(named:"250ps.png")
imageGuess.frame = CGRect(x: 51, y: 47, width: 500, height: 340)
imageIdentity = 1
}
else if rand3 == 2{
imageGuess.image = UIImage(named:"500ps.png")
imageGuess.frame = CGRect(x: 51, y: 47, width: 500, height: 340)
imageIdentity = 2
}
}
}
Klingt, als ob Sie einen Haltepunkt gesetzt haben. Deaktivieren oder löschen Sie den Haltepunkt. – ryantxr
Sie können den Anweisungen http://stackoverflow.com/questions/25750595/error-thread-1-breakpoint-1-1 hier folgen, um Breakpoints auszuschalten. – beyowulf