如何以编程方式滑动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];
}
}
但不正确。你能救我吗?
谢谢, 米克尔
答案 0 :(得分:2)
我希望能够在选择表格视图单元格时显示实用程序按钮,因此我在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:delegate方法中调用该方法。例如:
if (indexPath.row == 0) {
SWTableViewCell *cell = (SWTableViewCell *)[self.tableView cellForRowAtIndexPath:indexPath];
[cell showUtilityButtonsAnimated:YES];
}