tags | languages |
---|---|
pickerview, delegate, protocol |
objc |
One last delegate/protocol to warm up. Let's make a slot machine
- A picker View "displays a spinning wheel or slot-machine motif of values". I've already placed one on the storyboard. Your job is to implement it's 2 delegates.
- The first one is called
UIPickerViewDataSource
. Check out the docs on it...it should look pretty familiar fromUITableView
. Implement the required methods there to display the number of rows for all of the fruits. Also there should be three components. - Now implement the
UIPickerViewDelegate
to put in the appropriate text in each row. Each component (think column) should have the same stuff in it. - When the spin button is pressed, use the
selectRow:inComponent:animated:
to randomly spin each component to a row. - If they land on the same fruit, display a
UIAlertView
that says whether you won or lost. There should be two button:Cancel
andRe-spin
. These should do reasonable things.
As a sidenote: When you run the tests, you'll notice that the spinner will only show "Apple" and "Orange." We have "swizzled" the method so that winning spins become more likely (so that your tests don't run on and on forever.) Don't worry about how to do this for now, but understand that "swizzling" is the process of exchanging one method implementation for another. In this case we are substituting the original array of many fruits for one with just two fruits, just for the test suite. When run by a user, the array will include all of the fruits.