我定制了我的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设置为按下某些操作?
发布于 2017-09-28 20:33:12
当您按下按钮时,它将调用该块。
UITableViewRowAction *unlabelSpecies = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"UnLabel" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
{
CALL_YOUR_METHOD_FROM_HERE
}];
unlabelSpecies.backgroundColor = [UIColor darkGrayColor];
return @[unlabelSpecies];https://stackoverflow.com/questions/46477676
复制相似问题