質問

I'm creating and displaying an instance of UITableView. The delegate (which is actually my subclass of UITableView) never receives any of the following selectors:

  • tableView:shouldShowMenuForRowAtIndexPath:
  • tableView:canPerformAction:forRowAtIndexPath:withSender:
  • tableView:performAction:forRowAtIndexPath:withSender:

even though the documentation specifically states, for example, under the discussion of tableView:shouldShowMenuForRowAtIndexPath:

If the user tap-holds a certain row in the table view, this method (if implemented) is invoked first. Return NO if the editing menu shouldn’t be shown—for example, the cell corresponding to the row contains content that shouldn’t be copied or pasted over.

Other tutorials also document this shortcut for displaying the UIMenuController in table views. Why isn't this working as documented?

役に立ちましたか?

解決

Although it isn't currently documented (I'm submitting a documentation update, but who knows when/if it will be posted), the UITableViewDelegate methods:

  • tableView:shouldShowMenuForRowAtIndexPath:
  • tableView:canPerformAction:forRowAtIndexPath:withSender:
  • tableView:performAction:forRowAtIndexPath:withSender:

are only called if your table view instance is managed by an instance of UITableViewController. A standalone table view will not have these methods invoked.

If your table view isn't connected to a table view controller, then you'll need to display the UIMenuController manually from long tap listeners (to duplicate the standard system functionality) on each table view cell.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top