iOS Developer Library — Prerelease

Developer

UIKit Framework Reference UIResponderStandardEditActions Protocol Reference

Options
Deployment Target:

On This Page
Language:

UIResponderStandardEditActions

The UIResponderStandardEditActions informal protocol declares methods that responder classes should override to handle common editing commands invoked in the user interface, such as Copy, Paste, and Select.

Although this is an informal protocol—that is, a category declared on NSObject—it is recommended that responder classes (that is, immediate or distant ancestors of UIResponder) override its methods. Starting with the first responder, UIResponder looks for a responder object that can handle the method, and works up the responder chain from there. Responder classes may also implement the canPerformAction:withSender: method of UIResponder to disable or enable user-interface commands based on the context. The copy:, cut:, delete:, paste:, select:, and selectAll: methods are invoked when users tap the corresponding command in the menu managed by the UIMenuController shared instance.

  • Copy the selection to the pasteboard.

    Declaration

    Swift

    func copy(_ sender: AnyObject?)

    Objective-C

    - (void)copy:(id nullable)sender

    Parameters

    sender

    The object calling this method.

    Discussion

    This method is invoked when the user taps the Copy command of the editing menu. A subclass of UIResponder typically implements this method. Using the methods of the UIPasteboard class, it should convert the selection into an appropriate object (if necessary) and write that object to a pasteboard. The command travels from the first responder up the responder chain until it is handled; it is ignored if no responder handles it. If a responder doesn’t handle the command in the current context, it should pass it to the next responder.

    Availability

    Available in iOS 3.0 and later.

  • Remove the selection from the user interface and write it to the pasteboard.

    Declaration

    Swift

    func cut(_ sender: AnyObject?)

    Objective-C

    - (void)cut:(id nullable)sender

    Parameters

    sender

    The object calling this method.

    Discussion

    This method is invoked when the user taps the Cut command of the editing menu. A subclass of UIResponder typically implements this method. Using the methods of the UIPasteboard class, it should convert the selection into an appropriate object (if necessary) and write that object to a pasteboard. It should also remove the selected object from the user interface and, if applicable, from the application’s data model. The command travels from the first responder up the responder chain until it is handled; it is ignored if no responder handles it. If a responder doesn’t handle the command in the current context, it should pass it to the next responder.

    Availability

    Available in iOS 3.0 and later.

  • Remove the selection from the user interface.

    Declaration

    Swift

    func delete(_ sender: AnyObject?)

    Objective-C

    - (void)delete:(id nullable)sender

    Parameters

    sender

    The object calling this method.

    Discussion

    This method is invoked when the user taps the Delete command of the editing menu. A subclass of UIResponder typically implements this method by removing the selected object from the user interface and, if applicable, from the application’s data model. It should not write any data to the pasteboard. The command travels from the first responder up the responder chain until it is handled; it is ignored if no responder handles it. If a responder doesn’t handle the command in the current context, it should pass it to the next responder.

    Availability

    Available in iOS 3.2 and later.

    See Also

    – cut:

  • Read data from the pasteboard and display it in the user interface.

    Declaration

    Swift

    func paste(_ sender: AnyObject?)

    Objective-C

    - (void)paste:(id nullable)sender

    Parameters

    sender

    The object calling this method.

    Discussion

    This method is invoked when the user taps the Paste command of the editing menu. A subclass of UIResponder typically implements this method. Using the methods of the UIPasteboard class, it should read the data in the pasteboard, convert the data into an appropriate internal representation (if necessary), and display it in the user interface. The command travels from the first responder up the responder chain until it is handled; it is ignored if no responder handles it. If a responder doesn’t handle the command in the current context, it should pass it to the next responder.

    Availability

    Available in iOS 3.0 and later.

  • Select the next object the user taps.

    Declaration

    Swift

    func select(_ sender: AnyObject?)

    Objective-C

    - (void)select:(id nullable)sender

    Parameters

    sender

    The object calling this method.

    Discussion

    This method is invoked when the user taps the Select command of the editing menu. This command is used for targeted selection of items in the receiving view that can be broken up into chunks. This could be, for example, words in a text view. Another example might be a view that puts lists of visible objects in multiple groups; the select: command could be implemented to select all the items in the same group as the currently selected item.

    A subclass of UIResponder typically implements this method. The command travels from the first responder up the responder chain until it is handled; it is ignored if no responder handles it. If a responder doesn’t handle the command in the current context, it should pass it to the next responder.

    Availability

    Available in iOS 3.0 and later.

    See Also

    – selectAll:

  • Select all objects in the current view.

    Declaration

    Swift

    func selectAll(_ sender: AnyObject?)

    Objective-C

    - (void)selectAll:(id nullable)sender

    Parameters

    sender

    The object calling this method.

    Discussion

    This method is invoked when the user taps the Select All command of the editing menu. A subclass of UIResponder typically implements this method by selecting all objects in the current view. The command travels from the first responder up the responder chain until it is handled; it is ignored if no responder handles it. If a responder doesn’t handle the command in the current context, it should pass it to the next responder.

    Availability

    Available in iOS 3.0 and later.

    See Also

    – select:

  • Toggle the bold style information of the selected text.

    Declaration

    Swift

    func toggleBoldface(_ sender: AnyObject?)

    Objective-C

    - (void)toggleBoldface:(id nullable)sender

    Parameters

    sender

    The object calling this method.

    Discussion

    A subclass of UIResponder typically implements this method by applying a boldface style to the selected text if it does not currently have it, or by removing the style if it does. The command travels from the first responder up the responder chain until it is handled; it is ignored if no responder handles it. If a responder doesn’t handle the command in the current context, it should pass it to the next responder.

    Availability

    Available in iOS 6.0 and later.

  • Toggle the italic style information of the selected text.

    Declaration

    Swift

    func toggleItalics(_ sender: AnyObject?)

    Objective-C

    - (void)toggleItalics:(id nullable)sender

    Parameters

    sender

    The object calling this method.

    Discussion

    A subclass of UIResponder typically implements this method by applying an italic style to the selected text if it does not currently have it, or by removing the style if it does. The command travels from the first responder up the responder chain until it is handled; it is ignored if no responder handles it. If a responder doesn’t handle the command in the current context, it should pass it to the next responder.

    Availability

    Available in iOS 6.0 and later.

  • Toggle the underline style information of the selected text.

    Declaration

    Swift

    func toggleUnderline(_ sender: AnyObject?)

    Objective-C

    - (void)toggleUnderline:(id nullable)sender

    Parameters

    sender

    The object calling this method.

    Discussion

    A subclass of UIResponder typically implements this method by applying an underline style to the selected text if it does not currently have it, or by removing the style if it does. The command travels from the first responder up the responder chain until it is handled; it is ignored if no responder handles it. If a responder doesn’t handle the command in the current context, it should pass it to the next responder.

    Availability

    Available in iOS 6.0 and later.

  • Change the writing direction to left-to-right.

    Declaration

    Swift

    func makeTextWritingDirectionLeftToRight(_ sender: AnyObject?)

    Objective-C

    - (void)makeTextWritingDirectionLeftToRight:(id nullable)sender

    Parameters

    sender

    The object calling this method.

    Discussion

    A subclass of UIResponder typically implements this method by changing the current writing direction of its text editing area. The command travels from the first responder up the responder chain until it is handled; it is ignored if no responder handles it. If a responder doesn’t handle the command in the current context, it should pass it to the next responder.

    Availability

    Available in iOS 5.0 and later.

  • Change the writing direction to right-to-left.

    Declaration

    Swift

    func makeTextWritingDirectionRightToLeft(_ sender: AnyObject?)

    Objective-C

    - (void)makeTextWritingDirectionRightToLeft:(id nullable)sender

    Parameters

    sender

    The object calling this method.

    Discussion

    A subclass of UIResponder typically implements this method by changing the current writing direction of its text editing area. The command travels from the first responder up the responder chain until it is handled; it is ignored if no responder handles it. If a responder doesn’t handle the command in the current context, it should pass it to the next responder.

    Availability

    Available in iOS 5.0 and later.