UITableViewDelegate tableView canPerformAction forRowAtIndexPath withSender
- (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender
Parameters of [UITableViewDelegate tableView canPerformAction
tableView
The table-view object that is making this request.
action
A selector type identifying the copy: or paste: method of the UIResponderStandardEditActions informal protocol.
indexPath
An index-path object locating the row in its section.
sender
The object that initially sent the copy: or paste: message. T
Return Value of [UITableViewDelegate tableView canPerformAction forRowAtIndexPath withSender]
YES if the command corresponding to action should appear in the editing menu, otherwise NO. The default value is NO.
Discussion of [UITableViewDelegate tableView canPerformAction forRowAtIndexPath withSender]
This method is invoked after tableView:shouldShowMenuForRowAtIndexPath:. It gives the developer the opportunity to exclude one of the commands—Copy or Paste—from the editing menu. For example, the user might have copied some cell content from one row but wants to paste into another row that doesn’t take the copied content. In a case like this, return NO from this method.
UITableViewDelegate tableView canPerformAction forRowAtIndexPath withSender example.
-(void)copy:(id)sender {
[[UIPasteboard generalPasteboard] setString:detailTextLabel.text];
}
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
if(action == @selector(copy:)) {
return YES;
}
else {
return [super canPerformAction:action withSender:sender];
}
}
[[UIPasteboard generalPasteboard] setString:detailTextLabel.text];
}
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
if(action == @selector(copy:)) {
return YES;
}
else {
return [super canPerformAction:action withSender:sender];
}
}
Example of [UITableViewDelegate tableView canPerformAction forRowAtIndexPath withSender].
@interface MenuTableViewCell : UITableViewCell {
}
- (IBAction)copy:(id)sender;
- (void)showMenu;
@end
@implementation MenuTableViewCell
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (action == @selector(copy:)) {
return YES;
}
return NO;
}
- (IBAction)copy:(id)sender {
}
- (void)showMenu {
[[UIMenuController sharedMenuController] setMenuVisible:NO animated:YES];
[self becomeFirstResponder];
[[UIMenuController sharedMenuController] update];
[[UIMenuController sharedMenuController] setTargetRect:CGRectZero inView:self];
[[UIMenuController sharedMenuController] setMenuVisible:YES animated:YES];
}
@end
}
- (IBAction)copy:(id)sender;
- (void)showMenu;
@end
@implementation MenuTableViewCell
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (action == @selector(copy:)) {
return YES;
}
return NO;
}
- (IBAction)copy:(id)sender {
}
- (void)showMenu {
[[UIMenuController sharedMenuController] setMenuVisible:NO animated:YES];
[self becomeFirstResponder];
[[UIMenuController sharedMenuController] update];
[[UIMenuController sharedMenuController] setTargetRect:CGRectZero inView:self];
[[UIMenuController sharedMenuController] setMenuVisible:YES animated:YES];
}
@end
UITableViewDelegate tableView canPerformAction forRowAtIndexPath withSender example.
- (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)actionforRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender
{
NSLog(@"canPerformAction Method entered");
[self switchTitle:tableView indexPath:indexPath];
return YES;
}
{
NSLog(@"canPerformAction Method entered");
[self switchTitle:tableView indexPath:indexPath];
return YES;
}