滑动后UITableViewCell上的自定义按钮

时间:2012-01-17 10:14:00

标签: iphone objective-c ios ipad uitableview

在我的iPhone应用程序中,我有一个UITableView。 我希望在刷卡的同时在按钮上显示两个按钮,我希望它们如下所示:

  1. 按钮将是我自己的自定义按钮

  2. 按钮将显示一个小动画,就像苹果提供的普通删除按钮一样。

  3. 我有办法吗?

    感谢

2 个答案:

答案 0 :(得分:2)

我认为boilerplate.com最适合帮助您解决问题,它包含不同类型的细胞技术。也可以使用按钮滑动http://iosboilerplate.com/

答案 1 :(得分:0)

我做的是

        -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

UISwipeGestureRecognizer *swipeLeftRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
[swipeLeftRight setDirection:(UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft )];
[cell addGestureRecognizer:swipeLeftRight];

 -(void)handleGesture : (UIGestureRecognizer *)gec

{

    if (gec.state == UIGestureRecognizerStateEnded) {
    UITableViewCell *cell = (UITableViewCell *)gec.view;
    UIImageView *imgDelete = [[UIImageView alloc]initWithFrame:CGRectMake(cell.frame.size.width-40, 15, 35, 35)];
    UITapGestureRecognizer *deleteCell = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(deleteC)];
    [imgDelete addGestureRecognizer:deleteCell];
    imgDelete.image = [UIImage imageNamed:@"delete.png"];
    imgDelete.userInteractionEnabled = YES;
    [cell bringSubviewToFront:imgDelete];

    [UIView animateWithDuration:0.5
                     animations:^(void){
            [cell addSubview:imgDelete];
}completion:nil];}

}