Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SWTableViewCell display menu one at a time

Tags:

ios7

I am using SWTableViewCell for displaying my friendsList in tableView. Everything is working fine as per code. The thing is, I need only one cell to be active at a time. Right now I can swipe the menus of all the cells just by swiping one after the other. What i want is, when I am swiping on another cell the previous cell should turn to its original state.

This is my code for the cell

-(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;

}

like image 860
Abin George Avatar asked Feb 14 '23 05:02

Abin George


1 Answers

Implement this delegate method too..

- (BOOL)swipeableTableViewCellShouldHideUtilityButtonsOnSwipe:(SWTableViewCell *)cell {
    return YES;
}
like image 166
BangOperator Avatar answered Jun 07 '23 21:06

BangOperator