gpt4 book ai didi

ios - 当我们已经有一个单元格时尝试设置滑动以删除单元格....这看起来不太好

转载 作者:可可西里 更新时间:2023-11-01 03:32:22 25 4
gpt4 key购买 nike

单元格不允许删除它。当滑动发生时,它会向后滑动,因此无法删除它。控制台中的消息说:

attempting to set a swipe to delete cell when we already have one....
that doesn't seem good

代码:

#import "GroupDetailInfoViewController.h"
#import "YFJLeftSwipeDeleteTableView.h"

@interface GroupDetailInfoViewController ()

{
NSMutableArray * _dataArray;
UIButton * _deleteButton;
NSIndexPath * _editingIndexPath;

UISwipeGestureRecognizer * _leftGestureRecognizer;
UISwipeGestureRecognizer * _rightGestureRecognizer;
UITapGestureRecognizer * _tapGestureRecognizer;
}

@property (nonatomic, retain) YFJLeftSwipeDeleteTableView *tableView;
@end


@implementation GroupDetailInfoViewController

- (id)init
{
self = [super init];
if (self) {
// Custom initialization
_dataArray = [@[@(1), @(2), @(3), @(4), @(5), @(6), @(7), @(8), @(9), @(10)] mutableCopy];
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
CGRect frame = self.view.bounds;
self.tableView = [[YFJLeftSwipeDeleteTableView alloc] initWithFrame:frame];
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
[self.view addSubview:self.tableView];


}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return _dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.textLabel.text = [NSString stringWithFormat:@"Data at Row %@", _dataArray[indexPath.row]];

return cell;
}

// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}

// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[_dataArray removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}

}

- (void)tableView:(UITableView*)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"willBeginEditingRowAtIndexPath");
//[super setEditing:YES animated:YES];
[self.tableView setEditing:YES animated:YES];

//Self.editing handles the done / edit button
tableView.editing = YES;
}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCellEditingStyle editingStyle = UITableViewCellEditingStyleNone;
/*if (tableView.editing)*/ editingStyle = UITableViewCellEditingStyleDelete;

return editingStyle;
}

- (void)tableView:(UITableView*)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"didEndEditingRowAtIndexPath");
//[super setEditing:NO animated:YES];
[self.tableView setEditing:NO animated:YES];

//Self.editing handles the done / edit button
tableView.editing = NO;


}

- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
return NO;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 44;
}

@end

最佳答案

我在添加 SWTableViewCell 后遇到了同样的问题。我在已经实现 - (void)tableView:(UITableView)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath* 之后添加了 SWTableViewCell。

一旦我删除了这个方法,事情就按预期进行了。我猜想 SWTableViewCell 安装的 View 与试图基于此方法安装相同类型 View 的系统冲突。

关于ios - 当我们已经有一个单元格时尝试设置滑动以删除单元格....这看起来不太好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20786827/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com