SWTableViewCell display menu one at a time

I use SWTableViewCell to display my friends List in a tableView. Everything works fine according to the code. The fact is that I only need one cell to be active at a time. Right now, I can scroll through the menu of all cells, just making my way one by one. I want, when I scroll to another cell, the previous cell should go back to its original state.

This is my cell code

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSMutableArray *leftUtilityButtons = [NSMutableArray new];


[leftUtilityButtons sw_addUtilityButtonWithColor:
 [UIColor colorWithRed:0.07 green:0.75f blue:0.16f alpha:1.0]
                                            icon:[UIImage imageNamed:@"about-icon-md.png"]];
[leftUtilityButtons sw_addUtilityButtonWithColor:
 [UIColor colorWithRed:0.07 green:0.75f blue:0.16f alpha:1.0]
                                            icon:[UIImage imageNamed:@"chat-4-64.png"] ];
static NSString* identifier=@"addContactCell";

Cell *cell=(Cell *)[tableView dequeueReusableCellWithIdentifier:identifier];
Cell __weak * weakCell = cell;


[cell setAppearanceWithBlock:^{
    weakCell.containingTableView = tableView;


    weakCell.leftUtilityButtons = leftUtilityButtons;


    weakCell.delegate = self;
} force:NO];
if (cell==nil)
{

    SWTableViewCell *cell = (SWTableViewCell *)[tableView dequeueReusableCellWithIdentifier:identifier];

    if (cell == nil) {

        cell = [[SWTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
                                      reuseIdentifier:identifier
                                  containingTableView:self.table // Used for row height and selection
                                   leftUtilityButtons:leftUtilityButtons
                                  rightUtilityButtons:nil];
        cell.delegate = self;
    }
    return  cell;
    }

cell.backgroundColor=[UIColor clearColor];
[cell.contentView.layer setBorderColor:[UIColor colorWithRed:0.15f green:0.47f blue:0.17f alpha:0.1].CGColor];

[cell.contentView.layer setBorderWidth:1.0f];
indexvalueRow = indexPath.row;
indexValueSection =indexPath.section;

friendUser= [self findFriendUser];


[friendUser fetchIfNeededInBackgroundWithBlock:^(PFObject *object, NSError *error) {
    if (!error)
    {
        if (object) {


        NSLog(@"friend user = %@", friendUser);
        NSString *friendName = [NSString stringWithFormat:@"%@ %@", friendUser[@"FirstName"], friendUser[@"LastName"] ];


        cell.nameLabel.text= friendName;
        cell.nameLabel.textColor = [UIColor darkGrayColor];
        PFFile *userImageFile = friendUser[@"profilePic"];

        [userImageFile getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error)
         {

             if (!error) {

                 //NSLog(@"%@", imageData);
                 cell.profileImage.image = [UIImage imageWithData:imageData];


             }
         }];
        }}
}];


return cell;

}

+4
source share
1 answer

Implement this delegate method.

- (BOOL)swipeableTableViewCellShouldHideUtilityButtonsOnSwipe:(SWTableViewCell *)cell {
    return YES;
}
+7
source

Source: https://habr.com/ru/post/1536767/


All Articles