gpt4 book ai didi

iphone - 在 UITableViewCell 中启用/禁用编辑模式

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:16:33 24 4
gpt4 key购买 nike

我有一个自定义的 UITableViewCell,它有 1 个文本字段和一个标签。我只想在 tableview 处于编辑模式时启用文本字段编辑。

我正在使用以下方法启用文本字段编辑模式和禁用文本字段编辑模式。但这不起作用。我不确定这是否是正确的方法。如果这不是正确的方法,你能告诉我如何禁用启用文本字段吗?

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSIndexPath *rowToSelect = indexPath;
EditingTableViewCell *detSelCell;
detSelCell = (EditingTableViewCell *)[self.tableView cellForRowAtIndexPath:indexPath];
detSelCell.textField.enabled = self.editing;

// Only allow selection if editing.
if (self.editing)
{
return indexPath;
}
else
{
return nil;
}
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

if (!self.editing)
{
return;
}
EditingTableViewCell *detcell;
detcell = (EditingTableViewCell *)[self.tableView cellForRowAtIndexPath:indexPath];
detcell.selectionStyle = style;
detcell.textField.enabled = self.editing;

我还有以下几行:

self.tableView.allowsSelection = NO; // Keeps cells from being selectable while not editing. No more blue flash.
self.tableView.allowsSelectionDuringEditing = YES; // Allows cells to be selectable during edit mode.

请帮忙!

最佳答案

--- 我找到了答案:

我已经从以下方法中删除了启用/禁用代码:

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

并在 custom cell.m 中添加了以下内容

- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.1];
[UIView setAnimationDelegate:self];
[UIView setAnimationBeginsFromCurrentState:YES];

if(editing){
textField.enabled = YES;
}else{
textField.enabled = NO;
}

[UIView commitAnimations];
}

它现在正在工作。我不确定这是否是正确的方法,但它工作正常。

关于iphone - 在 UITableViewCell 中启用/禁用编辑模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9649986/

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