gpt4 book ai didi

ios - 设置按钮的标签值以在单元格单击时取消隐藏

转载 作者:行者123 更新时间:2023-11-29 00:21:44 26 4
gpt4 key购买 nike

我在 tableview 单元格上有一个按钮,它是以编程方式添加的,我使用 for 循环在每个单元格上添加了这个按钮,我也将它设置为“alpha 值 = 0”。我想要的是,当我点击特定的单元格时,它应该只显示该单元格上的按钮。

这是我所做的:

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{

if(tableView == self.todayTableView)
{
for (int i = 0; i < first.count; i++)
{
record1 = [UIButton buttonWithType: UIButtonTypeRoundedRect];

[record1 setAlpha:0];
record1.frame = CGRectMake(250, 23, 25, 25);

[record1 addTarget:self action:@selector(record:) forControlEvents:UIControlEventTouchUpInside];
[record1 setImage:[UIImage imageNamed:@"microphone-g-ico.png"] forState:(UIControlStateNormal)];

[cell addSubview:record1];

}
[record1 setTag:indexPath.row];
return cell;

}


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

if(indexPath.row == 0)
{

if( record1.tag == 8)
{
[record1 setAlpha:1];

}

}
}
}

当我点击单元格时,它只在最后一个单元格上显示按钮。

请建议??

最佳答案

改变这个===>

if(tableView == self.todayTableView)
{
for (int i = 0; i < first.count; i++)
{
record1 = [UIButton buttonWithType: UIButtonTypeRoundedRect];

[record1 setAlpha:0];
record1.frame = CGRectMake(250, 23, 25, 25);

[record1 addTarget:self action:@selector(record:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:record1];

}

到==>

  if(tableView == self.todayTableView)
{
for (__strong UIView *view in Cell.contentView.subviews) {
if(view.tag==101){
[view removeFromSuperview];
view = nil;}
}
record1 = [UIButton buttonWithType: UIButtonTypeRoundedRect];
record1.tag=101;
[record1 setAlpha:0];
record1.frame = CGRectMake(250, 23, 25, 25);

[record1 addTarget:self action:@selector(record:) forControlEvents:UIControlEventTouchUpInside];
[record1 setImage:[UIImage imageNamed:@"microphone-g-ico.png"] forState:(UIControlStateNormal)];

[Cell.contentView addSubview:record1];

}

/********替换 didSelect********************/

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(tableView == _todayTableView)
{
UITableViewCell *cell = [tableView
cellForRowAtIndexPath: indexPath];

for (__strong UIView *view in Cell.contentView.subviews) {
if(view.tag==101){
view.alpha=1;
break;
}


}
}

关于ios - 设置按钮的标签值以在单元格单击时取消隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44044784/

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