iOS Developer Library — Prerelease

Developer

Quick Look Framework Reference for iOS QLPreviewController Class Reference

Options
Deployment Target:

On This Page
Language:

QLPreviewController

A QLPreviewController object, or Quick Look preview controller, provides a specialized view for previewing an item. To display a Quick Look preview controller you have two options: You can push it into view using a UINavigationController object, or can present it modally, full screen, using the presentModalViewController:animated: method of its parent class, UIViewController.

A displayed preview includes a title taken from the last path component of the item URL. You can override this by implementing a previewItemTitle accessor for the preview item.

A Quick Look preview controller can display previews for the following items:

  • iWork documents

  • Microsoft Office documents (Office ‘97 and newer)

  • Rich Text Format (RTF) documents

  • PDF files

  • Images

  • Text files whose uniform type identifier (UTI) conforms to the public.text type (see Uniform Type Identifiers Reference)

  • Comma-separated value (csv) files

To use a Quick Look preview controller, you must provide a data source object. The data source provides preview items to the controller and tells it how many items to include in a preview navigation list. If there is more than one item in the list, a modally-presented (that is, full-screen) controller displays navigation arrows to let the user switch among the items. For a Quick Look preview controller pushed using a navigation controller, you can provide buttons in the navigation bar for moving through the navigation list.

For details on providing items to a preview controller, refer to QLPreviewControllerDataSource Protocol Reference and QLPreviewItem Protocol Reference for iOS.

  • Indicates whether or not the Quick Look preview controller can display an item.

    Declaration

    Swift

    class func canPreviewItem(_ item: QLPreviewItem) -> Bool

    Objective-C

    + (BOOL)canPreviewItem:(id<QLPreviewItem> _Nonnull)item

    Parameters

    item

    An item to be previewed.

    Return Value

    Returns YEStrue if the Quick Look preview controller can display the specified preview item.

    Discussion

    If an item cannot be displayed, but you still attempt to display it, a Quick Look preview controller displays a generic error. Always check if an item can be displayed before choosing whether or not to display it.

    Refer to this document’s Overview section (QLPreviewController) for the types of items that a Quick Look preview controller can display.

    Availability

    Available in iOS 4.0 and later.

  • The item currently displayed in the Quick Look preview controller. (read-only)

    Declaration

    Swift

    var currentPreviewItem: QLPreviewItem? { get }

    Objective-C

    @property(readonly, nullable) id< QLPreviewItem > currentPreviewItem

    Discussion

    If no item is being displayed, this property’s value is nil.

    Availability

    Available in iOS 4.0 and later.

  • The index, within the preview item navigation list, of the item currently displayed in the Quick Look preview controller.

    Declaration

    Swift

    var currentPreviewItemIndex: Int

    Objective-C

    @property NSInteger currentPreviewItemIndex

    Discussion

    You can change which item is displayed, among those in a navigation list, by setting this property’s value. If no item is being displayed, this property’s value is NSNotFound.

    Availability

    Available in iOS 4.0 and later.

  • Asks the Quick Look preview controller to recompute the display of the current preview item.

    Declaration

    Swift

    func refreshCurrentPreviewItem()

    Objective-C

    - (void)refreshCurrentPreviewItem

    Discussion

    The display is recomputed whether or not the current preview item has changed.

    Availability

    Available in iOS 4.0 and later.

  • Asks the Preview Controller to reload its data from its data source.

    Declaration

    Swift

    func reloadData()

    Objective-C

    - (void)reloadData

    Discussion

    The display is recomputed only if the current preview item has changed.

    Availability

    Available in iOS 4.0 and later.