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

Mark McCuller
Mark McCuller
3,539 Points

Build a Simple iPhone APP (iOS7)

In the Animating and Intercepting Events / Intercepting Touch Events: I see that you removed all the - (IBAction) buttonPressed methods from the .h and .m files in the video starting at time 3:03, why did we do this? At the end of the video you are using the touch events to change the predictions. How does the button work now when you touch the screen and/or globe and all the IBAction are all removed?

Thanks,

Mark

3 Answers

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

As mentioned in the beginning of that video. It was a design decision to get rid off the button all together so the user can see a prediction no matter where they click on the screen.

Mark McCuller
Mark McCuller
3,539 Points

Amit,

When you removed the IBAction methods how does the code know when you touch the screen to perform an action?

Thanks,

Mark

Boon Kiat Seah
Boon Kiat Seah
66,664 Points

The IBActions methods were wired to the predict button that was originally residing at the bottom. However, the button was removed. This is because Amit's design was to have the user perform a touch or a motion shake to make prediction.

When the IBAction methods were removed, the app is still generating predictions based on touch and motion shake. The methods came from the UIResponder Class and here is the url class reference file:

https://developer.apple.com/library/ios/documentation/uikit/reference/UIResponder_Class/Reference/Reference.html

Responding to Touch Events

  • touchesBegan:withEvent:
  • touchesMoved:withEvent:
  • touchesEnded:withEvent:
  • touchesCancelled:withEvent:

Responding to Motion Events

  • motionBegan:withEvent:
  • motionEnded:withEvent:
  • motionCancelled:withEvent:

These methods called the makePrediction method to generate the random prediction. Refer them in your THViewController file.

Feel free to correct me if i am wrong. Hope this helps.

Mark McCuller
Mark McCuller
3,539 Points

Boon,

Thank you for your explication on how the action works.

Mark