gpt4 book ai didi

ios - 在 UITableViewCell 中隐藏按钮

转载 作者:行者123 更新时间:2023-12-01 19:11:30 28 4
gpt4 key购买 nike

我目前有一个有 8 行的表,每行在右侧都有一个标签,在左侧有一个按钮。我希望我可以隐藏所有按钮,直到用户按下右上角的“编辑”按钮,然后它们会出现,允许用户与每个表格单元格进行交互。我不知道这是否可能,因为它们在 UITableViewCell s 或者是否有更简单的方法来为每个单元格召唤一个按钮

更新

好的,所以我已经放置了所有隐藏的属性,似乎没有错误,但应用程序无法识别其中任何一个。尽管它们被设置为最初隐藏,但这些按钮仍然不隐藏。这是我的代码

这是我的表格单元格代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:  (NSIndexPath      *)indexPath
{
static NSString *CellIdentifier = @"BlockCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

cell.textLabel.text = @"Free Block";

UIButton*BlockButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];

BlockButton.frame = CGRectMake(225.0f, 5.0f, 75.0f, 35.0f);
[BlockButton setTitle:@"Change" forState:UIControlStateNormal];
[BlockButton addTarget:self action:@selector(Switch:) forControlEvents:UIControlEventTouchUpInside];

Blockbutton.backgroundColor = [UIColor colorWithRed:102/255.f
green:0/255.f
blue:51/255.f
alpha:255/255.f];
Blockbutton.hidden = YES;
[cell addSubview:BlockButton];
return cell;
}

这是我的方法代码:
- (IBAction)Editmode:(UIButton *)sender 
{
Blockbutton.hidden = !Blockbutton.hidden;
[self.tableView reloadData];
}

关于可能是什么问题的任何想法或想法?

最佳答案

您需要创建一个 UITableViewCell如果您还没有子类。在该类中,覆盖 setEditing:animated:如果新值为 YES ,然后启用/添加/取消隐藏按钮。

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

if (editing) {
// add your button
someButton.hidden = NO;

} else {
// remove your button
someButton.hidden = YES;
}
}

这将是可选的,但如果 animated,我们鼓励您为更改设置动画。是 YES .

注意:这假设您已经连接了编辑按钮以更改 UITableView 的编辑模式.如果没有,请调用 setEditing:animated:UITableView在按钮 Action 中。这将自动调用 setEditing:animated:在每个可见的表格单元格上。

关于ios - 在 UITableViewCell 中隐藏按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16286255/

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