中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

自定義UITableViewCell 并修改cell的deleteButton

發布時間:2020-07-30 06:25:32 來源:網絡 閱讀:1598 作者:zql5666641 欄目:開發技術

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

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

出国| 曲水县| 盐山县| 特克斯县| 仪陇县| 景洪市| 项城市| 海宁市| 吐鲁番市| 柘城县| 大姚县| 大同县| 盐亭县| 静乐县| 龙岩市| 东方市| 宣化县| 沧源| 定襄县| 邮箱| 岳普湖县| 阿拉善右旗| 桃源县| 汕尾市| 樟树市| 泰兴市| 安远县| 邵东县| 紫金县| 保定市| 腾冲县| 建平县| 赤水市| 平和县| 礼泉县| 大余县| 南部县| 宜兰县| 东乌珠穆沁旗| 宁明县| 乌鲁木齐县|