Subscribe ( )

iPhone Programming Tutorials


 

Forum

You must be logged in to post Login Register

Search 

AppDelegate – NavController – viewController – view – touch event problem

User Post

8:38 am
September 4, 2008


paz

Noob

posts 2

1

Hi all,

If I have a touch event that is caught in my (UIView *) view (as this is the only place touch events can be caught, I believe) does anyone know how I can handle that event in my AppDelegate? I've been looking into the Responder Chain documentation but can't get it to work in practice. I've got as far as the viewController handling the message but can't get it to go any further up the chain.

Thanks for any help anyone can provide

Paz


10:09 am
September 4, 2008


HarryWang

Noob

posts 4

2

I don't think your AppDelegate will be able to handle a response.  AppDelegates usually inherit from the NSObject class and implement the UIApplicationDelegate protocol.  A responder inherits from the UIResponder base class (which of course inherits from the NSObject).

Maybe when declaring your AppDelegate, instead of inheriting from NSObject, inherit from NSResponder instead?  Don't know if it will need to “register” itself somewhere to receive the event notifications.

From the Apple docs:

—————————

A responder object is an object that can respond to events and handle them. UIResponder is the base class for all responder objects. It defines the programmatic interface not only for event handling but for common responder behavior. UIApplication, UIView, and all UIKit classes that descend from UIView (including UIWindow) inherit directly or indirectly from UIResponder.

The first responder is the responder object in the application (usually a UIView object) that is the current recipient of touches. A UIWindow objects sends the first responder an event in a message, giving it the first shot at handling the event. If the first responder doesn’t handle the event, it passes the event (via message) to the next responder in the responder chain to see if it can handle it.

The responder chain is a linked series of responder objects. It allows responder objects to delegate responsibility for handling an event to other, higher-level objects. An event proceeds up the responder chain as the application looks for an object capable of handling the event. The responder chain consists of a series of “next responders” in the following sequence:

  1. The first responder passes the event to its view controller (if it has one) and then on to its superview.

  2. Each subsequent view in the hierarchy similarly passes to its view controller first (if it has one) and then to its superview.

  3. The topmost enclosing view passes the event to the UIWindow object.

  4. The UIWindow object passes the event to the singleton UIApplication object.

If the application finds no responder object to handle the event, it discards the event.

———————

Good luck.

Harry “doesn't know if that will introduce more overhead though” Wang


7:36 am
September 5, 2008


paz

Noob

posts 2

3

HarryWang said:

I don't think your AppDelegate will be able to handle a response.  AppDelegates usually inherit from the NSObject class and implement the UIApplicationDelegate protocol.  A responder inherits from the UIResponder base class (which of course inherits from the NSObject).

Maybe when declaring your AppDelegate, instead of inheriting from NSObject, inherit from NSResponder instead?  Don't know if it will need to “register” itself somewhere to receive the event notifications.

From the Apple docs:

—————————

A responder object is an object that can respond to events and handle them. UIResponder is the base class for all responder objects. It defines the programmatic interface not only for event handling but for common responder behavior. UIApplication, UIView, and all UIKit classes that descend from UIView (including UIWindow) inherit directly or indirectly from UIResponder.

The first responder is the responder object in the application (usually a UIView object) that is the current recipient of touches. A UIWindow objects sends the first responder an event in a message, giving it the first shot at handling the event. If the first responder doesn’t handle the event, it passes the event (via message) to the next responder in the responder chain to see if it can handle it.

The responder chain is a linked series of responder objects. It allows responder objects to delegate responsibility for handling an event to other, higher-level objects. An event proceeds up the responder chain as the application looks for an object capable of handling the event. The responder chain consists of a series of “next responders” in the following sequence:

  1. The first responder passes the event to its view controller (if it has one) and then on to its superview.

  2. Each subsequent view in the hierarchy similarly passes to its view controller first (if it has one) and then to its superview.

  3. The topmost enclosing view passes the event to the UIWindow object.

  4. The UIWindow object passes the event to the singleton UIApplication object.

If the application finds no responder object to handle the event, it discards the event.

———————

Good luck.

Harry “doesn't know if that will introduce more overhead though” Wang



Hi Harry,

Thanks for your help. In fact your suggestion and some further reading led me to insert a main controller between my appDelegate and my viewControllers to handle these type of events and it seemed to work.

The docs I've been reading regarding the Responder chain to them have a distinct MAC OS feel to them rather than anything specific for the iPhone. May I ask where you found the information you sent to me?

Thanks again.

Paz

8:35 am
September 5, 2008


HarryWang

Noob

posts 4

4

“insert a main controller between my appDelegate and my viewControllers to handle these type of events”

That will work too!  I would surmise that would be the preferred method too.  Sorry I didn't think of it.

As for where I found that responder info, it was from pages 141 and 142 of the “iPhone OS Programming Guilde” PDF (although it is also online in the iPhone dev section).

Yeah, I read the responder stuff for non-iPhone platforms and there are a few different scenarios with it.  This little overview wraps it up a bit more succinctly.

Harry “thinks the Apple tech writers are a little too close to their areas of expertise…step back once in a while” Wang


Search 

About the iCodeBlog forum

Most Users Ever Online:

44


Currently Online:

3 Guests

Forum Stats:

Groups: 2

Forums: 6

Topics: 419

Posts: 893

Membership:

There are 934 Members

There has been 1 Guest

There are 2 Admins

There is 1 Moderator

Top Posters:

bobcubsfan – 54

crazyiez – 30

Uhu – 17

AdeC – 17

Nick – 15

jitesh61 – 12

Administrators: Brandon (88 Posts), Collin (0 Posts)

Moderators: VertigoSol (26 Posts)



©   

  • Posted by on 6 Aug 2008 in Uncategorized
  •   |  
  •   |  
  •   |  
  • Comments Off

Comments are closed.