# PFUIElementDelegate

A formal protocol declaring delegate messages sent by PFUIElement.

Extends Protocol: NSObject
Declared In: PFUIElement.h

##### Discussion

The PFUIElementDelegate protocol implements two optional delegate methods, PFUIElementWasDestroyed: and PFUIElementReportError:.

Clients that implement either of these delegate methods must declare that they adopt this formal protocol.

The PFUIElement.h header declares `PFUIElementWasDestroyedNotification`, an external notification posted when a UI element is destroyed in the user interface. Any client object can register to receive this notification. An object that implements the -PFUIElementWasDestroyed: delegate method is automatically registered to receive this notification.

## Groups

### OPTIONAL DELEGATE METHODS

#### Group members:

`-PFUIElementReportError:`

  Sent when an operation on the receiving UI element generates an accessibility error.

`-PFUIElementWasDestroyed:`

  Sent when a UI element is destroyed.

## Methods

`-PFUIElementReportError:`

  Sent when an operation on the receiving UI element generates an accessibility error.

`-PFUIElementWasDestroyed:`

  Sent when a UI element is destroyed.

### PFUIElementReportError:

Sent when an operation on the receiving UI element generates an accessibility error.

    - (void)PFUIElementReportError:(NSError *)error;

##### Parameters

`error`

  An NSError object containing information about the error.

##### Discussion

See -delegate and -setDelegate:.

### PFUIElementWasDestroyed:

Sent when a UI element is destroyed.

    - (void)PFUIElementWasDestroyed:(NSNotification *)notification;

##### Parameters

`notification`

  The notification parameter is always `PFUIElementWasDestroyedNotification`.

##### Discussion

Sent from the default notification center immediately after the receiving UI element is destroyed in the running application (for example, when a window closes).

The notification parameter is always `PFUIElementWasDestroyedNotification`. You can retrieve the destroyed PFUIElement object by sending `-object` to `notification`. Beware the warnings about using destroyed PFUIElement objects described in -elementRef.

If this method is implemented in the client, the client is automatically registered for `PFUIElementWasDestroyedNotification` when you set the element's delegate. Other classes can register with the default notification center to observe `PFUIElementWasDestroyedNotification` without implementing this delegate method.

If this element was registered by a client to be observed for accessibility notifications, destruction of this element will automatically unregister it for all registered notifications and update the observers' list of current registrations. This happens after this delegate message is sent and after `PFUIElementWasDestroyedNotification` is posted, to ensure that a client registered to receive `NSAccessibilityUIElementDestroyedNotification` from this element can respond before the registrations array is updated. (This means that implementors of this delegate method and observers of this notification must be aware that the current registrations array does not yet reflect the destruction of this element. If your delegate or notification method needs an up-to-date registrations array, you can force the registrations array to update by sending -unregisterForAllNotificationsFromElement:.)

Some UI elements do not report when their container is destroyed, such as a Cocoa window's title and grow area elements. The -exists method depends on this notification, so it will report that such elements still exist in the running application. See -exists for techniques that can be used to deal with this issue.

You can always safely get a destroyed UI element's -pid, and you can always test destroyed PFUIElement objects for equality using `-isEqual:` or -isEqualToElement:. You can also get information that was cached when a destroyed PFUIElement object was created, by sending -elementInfo, and the notification's `userInfo` dictionary also contains this information. See -elementInfo for information about the objects that are cached in the dictionary and their keys. The `userInfo` dictionary is autoreleased; the client must retain it if it is used.

A PFApplicationUIElement object never reports when it is destroyed (that is, when the application quits). It does not send this delegate message and it does not post the corresponding notification.

See also -delegate and -setDelegate:.

Last Updated: Saturday, July 10, 2010