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 trial

iOS Build a Vending Machine App in Swift 2.0 Displaying Additional Views Recap

Daniel Yoo
Daniel Yoo
3,812 Points

sender.value (UIStepper) does not reset

The reset() function sets the quantity back to 1, but when you select a different item and start adding/subtracting quantity, it does not start from 1. The quantity value jumps from the quantity value that was left off from previously selected item.

3 Answers

Martin Wildfeuer
PLUS
Martin Wildfeuer
Courses Plus Student 11,071 Points

Hey there, just had a look at the official download.

This seems to be a bug indeed. In order to also reset the stepper, you could create an outlet for your stepper. That is, the stepper itself, not the action. Just as with the other elements before, CTRL - click the stepper in storyboard and connect it to your view controller.

@IBOutlet weak var stepper: UIStepper!

This way, you can access the stepper and its' value directly. Then, in the reset() function, you could also reset the stepper value. Before, only the label was updated, but not the stepper value, just as you said.

func reset() {
    quantity = 1
    stepper.value = 1 // Reset the stepper 
    updateTotalPriceLabel()
    updateQuantityLabel()
}

Hope that makes sense :)

Pasan Premaratne, I did not follow that course, maybe this is worth mentioning. If it's up to the students to fix the little things, than probably not ;)

Daniel Yoo
Daniel Yoo
3,812 Points

Awesome. Thanks Martin!

That works!!!

Thank you!

Pasan Premaratne
STAFF
Pasan Premaratne
Treehouse Teacher

Will post a fix to this on Monday! Thanks for the heads up everyone and apologies for the error.

David Keck
David Keck
5,723 Points

Same problem, even in official download, FYI.

Martin Wildfeuer
Martin Wildfeuer
Courses Plus Student 11,071 Points

Sry, but I deleted our comments, as this was not a problem with your code but with the course. It's easier to follow this way.