How to change the image on the MGSwipeButton in MGSwipeTableCell

21 views Asked by At

enter image description here

   -(nullable NSArray<UIView*>*) swipeTableCell:(nonnull MGSwipeTableCell*) cell swipeButtonsForDirection:(MGSwipeDirection)direction
                               swipeSettings:(nonnull MGSwipeSettings*) swipeSettings expansionSettings:(nonnull MGSwipeExpansionSettings*) expansionSettings {
    swipeSettings.transition = MGSwipeTransition3D; // 滑出动画
    if (direction == MGSwipeDirectionRightToLeft) {
        expansionSettings.fillOnTrigger = YES;
               expansionSettings.threshold = 1.5;
               CGFloat padding = 10;
               MGSwipeButton *isTop = [MGSwipeButton buttonWithTitle:@"" icon:[UIImage imageNamed:@"top"] backgroundColor:[UIColor colorWithRed:243/256.0 green:243/256.0 blue:243/256.0 alpha:1] padding:padding callback:^BOOL(MGSwipeTableCell *sender) {
                   NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
                   TrackNumbersCellModel*model = self.dataSource[indexPath.row];
                   if (model.isTop) {
                      
                       model.isTop = NO;
                       [self.dataSource removeObject:model];
                       [self.dataSource insertObject:model atIndex:self.dataSource.count - 1];
                       [[TrackNumbersNetTools shareIntance] trackTable_MR_update_top_Entity:model.t_number isTop:NO];
                       [self.tableView reloadData];
                       
                   }else{
                       model.isTop = YES;
                       [self.dataSource removeObject:model];
                       [self.dataSource insertObject:model atIndex:0];
                       [[TrackNumbersNetTools shareIntance] trackTable_MR_update_top_Entity:model.t_number isTop:YES];
                       [self.tableView reloadData];
                   }
                   
                   return YES;
               }];
               [isTop centerIconOverTextWithSpacing:7];
               
               MGSwipeButton *isDelete = [MGSwipeButton buttonWithTitle:@"" icon:[UIImage imageNamed:@"delet"] backgroundColor:[UIColor colorWithRed:243/256.0 green:243/256.0 blue:243/256.0 alpha:1] padding:padding callback:^BOOL(MGSwipeTableCell *sender) {
                   NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
                   TrackNumbersCellModel*model = self.dataSource[indexPath.row];
                   [self.dataSource removeObjectAtIndex:indexPath.row];
                   [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
                   [[TrackNumbersNetTools shareIntance] trackTable_MR_deleteEntity:model.t_number onFinished:^{
                       if (self.deleteBlock) {
                           self.deleteBlock();
                       }
                   }];
                  
                   return YES;
               }];
               [isDelete centerIconOverTextWithSpacing:7];
               return @[isTop,isDelete];
    }
    
    return nil;
    
}

My problem is that when I click on the "isTop" MGSwipeButton. I tried to change the image on the MGSwipeButton and used the following method, but it didn't work. Please help. With a link to "MGSwipeTableCell":https://github.com/MortimerGoro/MGSwipeTableCell

-(BOOL)swipeTableCell:(MGSwipeTableCell*)cell tappedButtonAtIndex:(NSInteger)index direction:(MGSwipeDirection)direction fromExpansion:(BOOL)fromExpansion{
    if (direction == MGSwipeDirectionRightToLeft && index == 0) {
        id button = cell.leftButtons[index];
        MGSwipeButton * pressedBtn = button;
        [pressedBtn setImage:[UIImage imageNamed:@"yy"] forState:UIControlStateNormal];
        NSLog(@"pressedBtn title: %@",pressedBtn.titleLabel.text);}
    return YES;
}
0

There are 0 answers