• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Should touch events related to a given view be implemented in the view or the view controller?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Should touch events related to a given view be implemented in the view or the view controller?


  • Subject: Re: Should touch events related to a given view be implemented in the view or the view controller?
  • From: Jonathan Hess <email@hidden>
  • Date: Thu, 4 Jun 2009 18:00:10 -0700

Hey Michael -

It might help to approach this problem with the idea of "If I had multiple view controllers using this view, how would I make that work best".

Event handling is something you would normally manage at the UIView layer. After those events are handled, they're typically translated them into some sort of action, or delegate callback. The delegate call back that builds further meaning belongs in the view controller, but the event capturing and translation into some meaningful gesture should go in the view. UIButton for example tracks a touch and delivers an action. It's up to the button to track the touches, and a controller to receive the action and ascribe some meaning to it.

If you're view is completely generic, and you want to customize a specific instance of it for one view controller, then you should place your view customizing code in you're -[UIViewController viewDidLoad] override. If your view would want these customizations no matter what controller it was working with, you should place them in the view's awakeFromNib method.

Good Luck -
Jon Hess

On Jun 4, 2009, at 3:45 PM, Michael A. Crawford wrote:

Previously, I would have said the view-controller. But I just finished looking at the Metronome sample, which is included in the iPhone SDK. The touch handling code as well as some of the view initialization code (requiring a completely loaded view) is implemented in the UIView-derived class. Is this a bad example of how things should be partitioned or do I have the wrong idea about what the view-controller is for?

Here are some related follow-up questions:

1) What should be implemented in the view-controller?

2) Should all of the view properties be completely setup and configured within the view's own init and awakeFromNib methods or is the intent of viewDidLoad to allow for configuring view properties before proceeding?

Yeah, I'm confused.  Please discuss.  I will watch and learn.

-Michael
----------------------
The difference between genius and stupidity...
...is that genius has its limits."

-- Albert Einstein



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Should touch events related to a given view be implemented in the view or the view controller? (From: "Michael A. Crawford" <email@hidden>)

  • Prev by Date: Re: XIB and AppleGlot
  • Next by Date: Validating a NSSegmentedControl in a toolbar
  • Previous by thread: Should touch events related to a given view be implemented in the view or the view controller?
  • Next by thread: No Title Bar on NSPanel
  • Index(es):
    • Date
    • Thread