Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialIgor Alves
Courses Plus Student 4,115 Pointsi am trying to manage the fun facts app with different categories but something is going wrong
This is my view controller class, what is happening is that my assistFacts instance is being passed to the other view with a nil value and i don`t know why
import UIKit
class ViewController: UIViewController {
var imagesArray:[UIImageView] = []
@IBOutlet weak var ImageView0: UIImageView!
@IBOutlet weak var ImageView1: UIImageView!
@IBOutlet weak var ImageView2: UIImageView!
@IBOutlet weak var ImageView3: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
imagesArray.append(ImageView0)
imagesArray.append(ImageView1)
imagesArray.append(ImageView2)
imagesArray.append(ImageView3)
for index in 0..<imagesArray.count{
let Instance = assistantFacts(index: index)
let ImageIcons = imagesArray[index]
ImageIcons.image = Instance.Icon
ImageIcons.backgroundColor = Instance.backgroundColor
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue == "ShowAnotherViewSegue"{
let viewDestination = segue.destinationViewController as! ImportantViewController
// posso usar as propriedades q estao na importanVIewController agr
viewDestination.assistFacts = assistantFacts(index: 0)
}
}
@IBAction func ShowFunFacts(sender: AnyObject) {
performSegueWithIdentifier("ShowAnotherViewSegue", sender: sender)
}
}
this is my other view controller class
import UIKit
class ImportantViewController: UIViewController {
@IBOutlet weak var FunFactsLabel: UILabel?
@IBOutlet weak var SummaryLabel: UILabel?
var assistFacts: assistantFacts?
override func viewDidLoad() {
super.viewDidLoad()
if assistFacts == nil{
print("ok")
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func ShowAnotherFunFactButton(sender: AnyObject) {
let AssistantFactsPicked = assistFacts!.funFactsArray
let auxiliar = arc4random_uniform(UInt32(AssistantFactsPicked.count))
let randomNumber = Int(auxiliar)
FunFactsLabel?.text = AssistantFactsPicked[randomNumber]
}