Ios 将自定义UITableViewCell返回到非编辑状态
我已将UITableViewCell子类化,以便为我的表视图创建自定义布局和动画。基本上,当我向左滑动时,我进入编辑模式,当我向右滑动时,我退出编辑模式——每一个都有相应的动画 滑动按预期工作,但我似乎不知道如何在表格视图滚动或其他单元格进入编辑状态时将单元格设置为非编辑状态 这个想法是每当tableview滚动或用户开始编辑(向左滑动)另一个单元格时,将单元格重置为“正常”状态 以下是我的自定义UITableViewCell类:Ios 将自定义UITableViewCell返回到非编辑状态,ios,uitableview,sdk,Ios,Uitableview,Sdk,我已将UITableViewCell子类化,以便为我的表视图创建自定义布局和动画。基本上,当我向左滑动时,我进入编辑模式,当我向右滑动时,我退出编辑模式——每一个都有相应的动画 滑动按预期工作,但我似乎不知道如何在表格视图滚动或其他单元格进入编辑状态时将单元格设置为非编辑状态 这个想法是每当tableview滚动或用户开始编辑(向左滑动)另一个单元格时,将单元格重置为“正常”状态 以下是我的自定义UITableViewCell类: // // CustomTableViewCell.m //
//
// CustomTableViewCell.m
//
// Created by Spencer Müller Diniz on 27/03/13.
// Copyright (c) 2013 Family. All rights reserved.
//
#import "CustomTableViewCell.h"
@implementation CustomTableViewCell
@synthesize customView;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
CGRect customFrame = CGRectMake(0.0f, 0.0f, self.contentView.bounds.size.width, self.contentView.bounds.size.height);
self.customView = [[CustomTableViewCellView alloc] initWithFrame:customFrame];
[self.contentView addSubview:self.customView];
UISwipeGestureRecognizer* sgrLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(cellSwipedLeft:)];
[sgrLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[self addGestureRecognizer:sgrLeft];
UISwipeGestureRecognizer* sgrRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(cellSwipedRight:)];
[sgrRight setDirection:UISwipeGestureRecognizerDirectionRight];
[self addGestureRecognizer:sgrRight];
}
return self;
}
- (void)cellSwipedLeft:(UIGestureRecognizer *)gestureRecognizer {
if (!self.isEditing)
[self setEditing:YES animated:YES];
}
- (void)cellSwipedRight:(UIGestureRecognizer *)gestureRecognizer {
if (self.isEditing)
[self setEditing:NO animated:YES];
}
- (void)layoutSubviews {
if (self.isEditing) {
[UIView animateWithDuration:0.5f animations:^{
self.customView.forgroundView.frame = CGRectMake(-100.0f, 0.0f, self.customView.forgroundView.frame.size.width, self.customView.forgroundView.frame.size.height);
}];
}
else {
[UIView animateWithDuration:0.5f animations:^{
self.customView.forgroundView.frame = CGRectMake(0.0f, 0.0f, self.customView.forgroundView.frame.size.width, self.customView.forgroundView.frame.size.height);
}];
}
}
@end
UITableView是UIScrollView的一个子类。因此,当您开始滚动表格时,将调用委托scrollViewDidScroll。因此,在学员内部,您可以进行必要的更改。感谢您的建议。我尝试在scrollViewDidScroll中调用[self.tableView setEditing:NO animated:YES],希望这样可以将正在编辑的每个单元格设置为正常状态,但它不起作用。是否调用代理?是否希望每个单元格有不同的行为?@Anil,是的,正在调用它(通过NSLog确认)。