我如何以编程方式滑动SWTableViewCell。

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

我努力了:
 [[[SWTableViewCell alloc]init]didTransitionToState:2];

并在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];
}

}

但不正确。你能帮助我吗?

谢谢,
米克尔

最佳答案

我希望能够在选择表格视图单元时显示实用程序按钮,因此我在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];
}

}

并且不要忘记将其添加到SWTableViewCell.h
- (void)showUtilityButtonsAnimated:(BOOL)animated;

然后从-tableView:didSelectRowAtIndexPath:委托方法中调用该方法。例如:
if (indexPath.row == 0) {
    SWTableViewCell *cell = (SWTableViewCell *)[self.tableView cellForRowAtIndexPath:indexPath];
    [cell showUtilityButtonsAnimated:YES];
}

关于ios - 以编程方式编写SWTableViewCell幻灯片,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25891110/

10-08 23:30