CEWendel / SWTableViewCell

An easy-to-use UITableViewCell subclass that implements a swippable content view which exposes utility buttons (similar to iOS 7 Mail Application)
MIT License
7.14k stars 1.27k forks source link

Sample code for show just one menu in tableview #427

Closed Husseinhj closed 10 months ago

Husseinhj commented 5 years ago

If you want to just show a single swipe menu in TableView can try with my sample:

Create a property the keep last cell has shown the menu.

@interface MyViewController ()<UITableViewDelegate,UITableViewDataSource ,SWTableViewCellDelegate>

@property (nonatomic, strong) SWTableViewCell *lastSWCell;

@end

Then implement this code to hide the menu of the last cell has been shown.

-(void) swipeableTableViewCell:(SWTableViewCell *)cell scrollingToState:(SWCellState)state{
    if (state != kCellStateCenter) {
        if (self.lastSWCell) {
            [self.lastSWCell hideUtilityButtonsAnimated:YES];
        }
        self.lastSWCell = cell;
    }
}

If you want to hide the menu when user scrolled the TableView implement this:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if (self.lastSWCell) {
        [self.lastSWCell hideUtilityButtonsAnimated:YES];
        self.lastSWCell = nil;
    }
}

SampleVideo