iOS自定义UITableView单元格按钮

时间:2012-12-21 09:07:40

标签: ios uitableview uibutton swipe

我希望当用户滑动表格视图单元格时,显示多个编辑按钮(默认为删除按钮)。是否可以在tableView:tableView editingStyleForRowAtIndexPath:方法中放置自定义按钮?

2 个答案:

答案 0 :(得分:0)

将Gesture识别器添加到您的班级,并在其选择器中尝试下面的内容。

-(void)cellDidSwipeLeft:(UIGestureRecognizer *)_gestureRecognizer
{
     if(_gestureRecognizer.state == UIGestureRecognizerStateEnded)
     {
         CGPoint swipeLocation = [_gestureRecognizer locationInView:self.tableView];

            NSIndexPath *swipedIndexPath = [self.tableView indexPathForRowAtPoint:swipeLocation];


            UITableViewCell* swipedCell = (UITableViewCell *)[self.tableView cellForRowAtIndexPath:swipedIndexPath];
            YourCustomBtn *Btn = (YourCustomBtn *)[swipedCell viewWithTag:999];

            [self performAnimationOnObject:Btn forPoint:swipeLocation];
      }
}





-(void)performAnimationOnObject:(id)view forPoint:(CGPoint)point
    {
     CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
        animation.delegate = self;
        animation.fromValue = [NSValue valueWithCGPoint:CGPointMake(btn.superview.frame.size.width, btn.center.y)];
                animation.toValue = [NSValue
                                     valueWithCGPoint:CGPointMake(mainCleanFrame.origin.x, btn.center.y)];
                animation.fillMode = kCAFillModeForwards;
                btn.center = CGPointMake(btn.frame.origin.x, btn.center.y);
    }

答案 1 :(得分:0)

我创建了一个新的库来实现可交换按钮,它支持各种转换和可扩展按钮,如iOS 8邮件应用程序。

https://github.com/MortimerGoro/MGSwipeTableCell

该库兼容所有不同的创建UITableViewCell的方法,并在iOS 5,iOS 6,iOS 7和iOS 8上进行测试。

enter image description here