【发布时间】:2017-09-28 20:21:57
【问题描述】:
我自定义了 UITableCellDeleteConfirmationView 以更改 iOS 8 及更高版本中按钮的背景颜色。 Following this post,我实现了editActionsForRowAtIndexPath、commitEditingStyle 和canEditRowAtIndexPath。
-(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
RankedSpecies* rankedSpecies = [fetchedResultsController objectAtIndexPath:indexPath];
if ( [self.collectedLeaf.selectedSpecies isEqualToString:[rankedSpecies.Species commonNameFirstLast]] )
{
UITableViewRowAction *unlabelSpecies = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"UnLabel" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
{
NSLog(@"Action to perform with Button 1");
}];
unlabelSpecies.backgroundColor = [UIColor darkGrayColor];
return @[unlabelSpecies];
}
UITableViewRowAction *labelSpecies = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Label" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
{
NSLog(@"Action to perform with Button 1");
}];
labelSpecies.backgroundColor = [UIColor darkGrayColor];
return @[labelSpecies];
}
但是,当我按下这些自定义按钮时,它们不会调用 commitEditingStyle。 According to this post, commitEditingStyle 仅在您触摸删除按钮时触发。
我没有试图弄清楚如何触发commitEditingStyle,而是创建了复制我的commitEditingStyle 实现removeCollectedLeafLabel 的方法。 类方法可以是动作吗?如何设置 UITableViewRowAction 在按下时执行某些操作?
【问题讨论】:
标签: ios objective-c uitableview uitableviewrowaction