gpt4 book ai didi

iphone - editStyleForRowAtIndexPath 没有被调用(因此显示删除按钮)

转载 作者:行者123 更新时间:2023-12-03 19:33:58 25 4
gpt4 key购买 nike

我正在尝试移动 uitableviewcells,无论出于何种原因,

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
editingstyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleNone; //<-- bp set on it
}

没有被调用(我已经在上面设置了一个断点) - 所以表显示了删除选项,但我不希望这样。这是我的实现:

@implementation MoveItController
@synthesize mList;

- (IBAction)moveButton
{
[self.tableView setEditing:!self.tableView.editing animated:YES];

[self.navigationItem.rightBarButtonItem setTitle:(self.tableView.editing)? @"Done" : @"Move"];
}

- (void)viewDidLoad
{
if (mList == nil)
{
mList = [[NSMutableArray alloc] initWithObjects:@"$1", @"$2", @"$5", @"$10", @"$20", @"$50", @"$100", nil];
}

UIBarButtonItem *mvButton = [[UIBarButtonItem alloc]
initWithTitle:@"Move"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(moveButton)];
self.navigationItem.rightBarButtonItem = mvButton;
[mvButton release];
[super viewDidLoad];
}

// Table datasource methods

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [mList count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *moveItCellId = @"moveItCellId";


UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:moveItCellId];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:moveItCellId] autorelease];
cell.showsReorderControl = YES;
}

cell.textLabel.text = [mList objectAtIndex:[indexPath row]];
return cell;
}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
editingstyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleNone;
}

- (BOOL)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath
toIndexPath:(NSIndexPath *)toIndexPath
{
id object = [[mList objectAtIndex:[fromIndexPath row]] retain];
[mList removeObjectAtIndex:[fromIndexPath row]];
[mList insertObject:object atIndex:[toIndexPath row]];
[object release];
}

- (void) dealloc
{
[mList release];
[super dealloc];
}

@end

编译时没有警告。

谢谢!

最佳答案

需要在编辑模式下将多选设置为NO

self.tableview.allowsMultipleSelectionDuringEditing = NO;

关于iphone - editStyleForRowAtIndexPath 没有被调用(因此显示删除按钮),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2226509/

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