gpt4 book ai didi

ios - 我无法从自定义 UITableViewCell 中删除自定义 UIButton

转载 作者:行者123 更新时间:2023-11-28 22:10:59 24 4
gpt4 key购买 nike

在编辑模式下,除了编辑附件之外,我还希望单元格显示一个 uibutton。当 tableView 进入编辑模式时,按钮显示正常并且工作正常。但它永远不会被删除。除了以下代码之外,我还尝试说 myButton.hidden = TRUE。这就是我在自定义 tableViewCell 类中的内容

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];

self.trashButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.trashButton.frame = CGRectMake(337, 17, 27, 30);
[self.trashButton setBackgroundImage:[UIImage imageNamed:@"trash.png"] forState:UIControlStateNormal];

if (editing) {
[self addSubview:self.trashButton];
} else {

[self.trashButton removeFromSuperview];
}
}

最佳答案

正如我在上面的评论中提到的,这样做可能会更好:

- (void)setEditing:(BOOL)editing animated:(BOOL)animated 
{
[super setEditing:editing animated:animated];

if (self.trashButton)
{
[self.trashButton removeFromSuperview];
self.trashButton = nil;
}
else
{
self.trashButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.trashButton.frame = CGRectMake(337, 17, 27, 30);
[self.trashButton setBackgroundImage:[UIImage imageNamed:@"trash.png"] forState:UIControlStateNormal];

[self addSubview:self.trashButton];
}
}

关于ios - 我无法从自定义 UITableViewCell 中删除自定义 UIButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22950927/

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