Mono Class Library: MonoTouch.UIKit Namespace

MonoTouch.UIKit.UIPasteboard Class

Support for the system pasteboard for cut, copy and paste.

See Also: UIPasteboard Members

System.Object
     MonoTouch.Foundation.NSObject
          MonoTouch.UIKit.UIPasteboard

[MonoTouch.Foundation.Register("UIPasteboard")]
public class UIPasteboard : MonoTouch.Foundation.NSObject

Remarks

Overview

The UIPasteboard class enables an application to share data within the application or with another application using system-wide or application-specific pasteboards.

Typically, an object in the application writes data to a pasteboard when the user requests a copy or cut operation on a selection in the user interface. Another object in the same or different application then reads that data from the pasteboard and presents it to the user at a new location; this usually happens when the user requests a paste operation.

A pasteboard is a named region of memory where data can be shared. There are two system pasteboards: the General pasteboard (UIPasteboardNameGeneral) and the Find pasteboard (UIPasteboardNameFind. You can use the General pasteboard for copy-paste operations involving any kind of data; the Finder pasteboard, which is used in search operations, holds the most recent string value in the search bar. Applications can also create pasteboards for their own use or for use by a family of related applications. Pasteboards must be identified by a unique names. You may also mark an application pasteboard as persistent, so that it continues to exist past the termination of the application. System pasteboards are persistent by default.

When you write an object to a pasteboard, it is stored as a pasteboard item. A pasteboard item is one or more key-value pairs where the key is a string that identifies the representation type of the value. Having multiple representation types per pasteboard item makes it more possible for one application to share data with another application without having to know specific capabilities of that application. For example, the source application could write the same image to the pasteboard in PNG, JPEG, and GIF data formats. If the receiving application can only handle GIF images, it can still obtain the pasteboard data.

A Uniform Type Identifier (UTI) is frequently used for a representation type (sometimes called a pasteboard type). For example, you could use kUTTypeJPEG (a constant for public.jpeg) as a representation type for JPEG data. However, applications are free to use any string they want for a representation type; however, for application-specific data types, it is recommended that you use reverse-DNS notation to ensure the uniqueness of the type (for example, com.myCompany.myApp.myType).

Note: For a discussion of Uniform Type Identifiers and a list of common ones, see Uniform Type Identifiers Overview.

UIPasteboard provides methods for reading and writing single pasteboard items at a time as well as multiple pasteboard items. The data written and read can be in two general forms. If the data to be written is a property-list objects or can be converted to such an object, use a method such as UIPasteboard.SetValue(MonoTouch.Foundation.NSObject, string) to write it to the pasteboard. If the data is binary (say, image data) or can’t be converted to a property-list type, you would use the UIPasteboard.SetData(MonoTouch.Foundation.NSData, string) to write it to the pasteboard. For UIPasteboard, the classes of the property-list objects are NSString, NSArray, NSDictionary, NSDate, NSNumber and NSURL. The class also provides convenience methods for writing and reading strings, images, URLs, and colors to and from single or multiple pasteboard items.

Although UIPasteboard is central to copy-paste operations, several other UIKit classes and protocols are used in these operations as well:

An application that implements copy-paste usually has to handle the management and presentation of selections in its user interface. It must also coordinate the addition and removal of items via paste and cut operations with its data model.

Requirements

Namespace: MonoTouch.UIKit
Assembly: monotouch (in monotouch.dll)
Assembly Versions: 0.0.0.0