March 2013
Intermediate to advanced
1000 pages
34h 51m
English
It is possible to display a menu from a table view cell by performing a long press on the cell. A menu, in iOS, is a sort of balloon containing tappable words such as Copy, Cut, and Paste. And as far as I can tell, those are the only words you’ll be including in a table view cell’s menu; I tried to customize the menu to include other terms, but I failed.
To allow the user to display a menu from a table view’s cells, you implement three delegate methods:
tableView:shouldShowMenuForRowAtIndexPath:
tableView:canPerformAction:forRowAtIndexPath:withSender:
cut:, copy:, and paste:. Whichever ones you respond YES to will appear in the menu; returning YES, regardless, causes all three menu items to appear in the menu. The menu will now appear unless you return NO to all three actions. The sender is the shared UIMenuController, which I’ll discuss more in Chapter 23 and Chapter 39.
tableView:performAction:forRowAtIndexPath:withSender:
Here’s an example where the user can summon a Copy menu from any cell (Figure 21-10):
- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath { return ...Read now
Unlock full access