Mikel Diaz
Mikel Diaz

Reputation: 43

SWTableViewCell slide programmatically

How can i slide programmatically SWTableViewCell.

//When i click in a cell i want to open the swtableviewcell
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  ???
}

i have tried:

 [[[SWTableViewCell alloc]init]didTransitionToState:2];

and in swtableviewcell.m

-(void)didTransitionToState:(UITableViewCellStateMask)state{
NSLog(@"state: %lu",state);
if (_cellState == kCellStateCenter)
{
    [self.cellScrollView setContentOffset:[self contentOffsetForCellState:kCellStateRight] animated:YES];
    [self.delegate swipeableTableViewCell:self scrollingToState:kCellStateRight];
}

}

but is not correct. Can you help me?

Thanks, Mikel

Upvotes: 1

Views: 1511

Answers (1)

user3841460
user3841460

Reputation: 205

I wanted to be able to show the utility buttons when a table view cell was selected so I added a method in SWTableViewCell.m

-(void)showUtilityButtonsAnimated:(BOOL)animated {    
// Force the scroll back to run on the main thread because of weird scroll view bugs
dispatch_async(dispatch_get_main_queue(), ^{
    [self.cellScrollView setContentOffset:CGPointMake(0, 0) animated:YES];
});
_cellState = kCellStateLeft;

if ([self.delegate respondsToSelector:@selector(swipeableTableViewCell:scrollingToState:)])
{
    [self.delegate swipeableTableViewCell:self scrollingToState:kCellStateCenter];
}

}

and don't forget to add it to SWTableViewCell.h

- (void)showUtilityButtonsAnimated:(BOOL)animated;

Then call that method from within your -tableView:didSelectRowAtIndexPath: delegate method. For example:

if (indexPath.row == 0) {
    SWTableViewCell *cell = (SWTableViewCell *)[self.tableView cellForRowAtIndexPath:indexPath];
    [cell showUtilityButtonsAnimated:YES];
}

Upvotes: 2

Related Questions