ios - SWTableViewCell 以编程方式滑动

标签 ios objective-c uitableview slide

我如何以编程方式滑动 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];
}

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

谢谢, 米克尔

最佳答案

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

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

相关文章:

ios - 自上次 Xcode 更新以来,我无法处理图像

ios - Swift 如何正确更新 UITableViewCell 约束

ios - 在 UITableView 中显示单元格的奇怪问题

ios - CLLocation- 用户位置在 App 恢复时丢失(零纬度和经度)

ios - 找出按钮属于哪个 UITableView

ios - 应用程序在 IOS 6 上崩溃 - UIViewControllerHierarchyInconsistency

ios - JSON 未转换为 NSString

ios - 从其他地方合并 @Published 属性 : get current value during update,

objective-c - NSWindowController 中的 socket 失败错误

ios - 如何将自定义单元格放入另一个自定义单元格?