views:

259

answers:

3

I know about these notifications on the iPhone, as you may need them to scroll a text view into place when they are obscured by the keyboard:

  • UIKeyboardWillShowNotification
  • UIKeyboardDidShowNotification
  • UIKeyboardWillHideNotification
  • UIKeyboardDidHideNotification

Right now, I have a some value that I want to update each time the user enters some input, using ANY control. But I'm dealing with all sorts of different controls here - TextViews, TextFields, Pickers, SegmentedViews, etc.

Is there a way that I can register for a notification that is sent by all UIResponders?

I'm looking for types of notifications other than the ones listed above - is there a definitive list anywhere?

A: 

I'm not sure if I get your question right, but you can register for notifications sent by any object by passing nil for the object argument when adding your observer:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(keyboardExposes:)
                                             name:UIKeyboardWillShowNotification
                                           object:nil];

After understanding your question better I appended this:

There's no definite list of all notifications since their type (name) is only a string and anybody can invent new notifications (including for private use only). But you can easily list the declared notifications from the iPhone SDK:

find  /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.1.sdk/ \
  -name "*.h" -exec cat {} \; \
  | grep -E "NSString[[:space:]]*\*[[:space:]]*(const)?[[:space:]]*[[:alnum:]]+Notification" \
  | grep -E -o "[[:alnum:]]+Notification"

This lists 46 notifications.

Nikolai Ruhe
I'm looking for other types of notifications, other than the ones I listed, that I may be able to leverage for tracking other events.
bpapa
A: 

If you want to receive all notifications, just register with the name as nil as well:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(handleNotification:)
                                             name:nil
                                           object:nil];

You can then determine what notifications you actually want to deal with after finding out which ones you can receive.

Ed Marty
+1  A: 

In theory from looking at the types of events you can attach to an action in IB, valueChanged would be perfect (these are not notifications).

Sadly that is not fired by all types of responders. So there's not a good universal way to do so... perhaps put together a class that has methods to handle all types of actions and tie in whatever makes sense for the elements on a page.

Kendall Helmstetter Gelner