//
// Cell.h
// Demo2
//
// Created by apple-zql on 13-6-19.
// Copyright (c) 2013年 qian bodong. All rights reserved.
//

#import <UIKit/UIKit.h>


@protocol myCellDelegate <NSObject>

- (void)commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;

@end

@interface myCell : UITableViewCell

@property (nonatomic, assign) id<myCellDelegate> *myCellDelegate;
@property (nonatomic, retain) NSIndexPath *indexPath;

@end






//
// Cell.m
// Demo2
//
// Created by apple-zql on 13-6-19.
// Copyright (c) 2013年 qian bodong. All rights reserved.
//

#import "myCell.h"
#import <UIKit/UIControl.h>
#import <QuartzCore/QuartzCore.h>
@implementation myCell

@synthesize indexPath;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];

// Configure the view for the selected state
}


- (void)layoutSubviews
{
[super layoutSubviews];

// NSLog(@"row is %d",row);
for (UIView *subview in self.subviews) {
if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"]) {

for (UIView *v in subview.subviews) {
v.hidden = YES;
if (self.showingDeleteConfirmation == NO)
{
[self.layer removeAllAnimations];
[UIView animateWithDuration:0.4f animations:^(void){
[subview viewWithTag:101].frame = CGRectMake(6, 4, 63, 34);
}completion:^(BOOL finished) {
[[subview viewWithTag:101] removeFromSuperview];
[[subview viewWithTag:100] removeFromSuperview];
}];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
break;
}

if (self.showingDeleteConfirmation == YES) {
UIButton *delbuton = [[UIButton alloc] initWithFrame:CGRectMake(6, 4, 63, 34)];
[delbuton setImage:[UIImage p_w_picpathNamed:@"btn06_on(delete)_bookmark@2x.png"] forState:UIControlStateNormal];
[delbuton addTarget:self action:@selector(deleteBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
delbuton.tag = 100;
[subview addSubview:delbuton];
UIView *layer_view = [[UIView alloc] init];
layer_view.frame = CGRectMake(6, 4, 63, 34);
layer_view.backgroundColor = [UIColor whiteColor];
layer_view.tag = 101;
[subview addSubview:layer_view];

[UIView beginAnimations:@"me" context:nil];
[UIView setAnimationDuration:0.4f];
layer_view.frame = CGRectMake(6, 4, 0, 34);
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView commitAnimations];
[delbuton release];
[layer_view release];
break;
}
}
}
}
}


- (void) willTransitionToState:(UITableViewCellStateMask)state{
[super willTransitionToState:state];
// NSLog(@"row is %d row",row);
//UITableViewCellStateShowingDeleteConfirmationMask
if ((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableViewCellStateShowingDeleteConfirmationMask) {
for (UIView *subview in self.subviews) {
if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"]) {
//this is delete button

}

if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellContentView"]) {
//this is contentView

}
}
}
//UITableViewCellStateDefaultMask
if ((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableViewCellStateDefaultMask){
for (UIView *subview in self.subviews) {
if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"]) {
//this is delete button
}

if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellContentView"]) {
//this is contentView

}
}
}
NSLog(@" delete show %d",self.showingDeleteConfirmation);
}

- (void) deleteBtnClicked:(id)sender
{
[(id)self.myCellDelegate commitEditingStyle:UITableViewCellEditingStyleDelete forRowAtIndexPath:indexPath];
}

- (void)didTransitionToState:(UITableViewCellStateMask)state
{
[super didTransitionToState:state];
}
@end

然后 在Viewcontroller中实现 delegate的方法即可