Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,640 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