自定义UITableViewCell 并修改cell的deleteButton

发布时间:2020-07-30 06:25:32 作者:zql5666641
来源:网络 阅读:1598

//
//  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的方法即可

推荐阅读:
  1. iOS 8 UITableViewCell 分割线 左对齐
  2. IOS uitableviewcell 左滑 自定义

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

uitableviewcell 修改d ce

上一篇:Ajax 学习

下一篇:整合公司3个网站后台管理子系统的经验总结 - 实现多系统的单点登录(ASP.NET + ASP)

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》