Ios 如何通过单击UITableViewCell中的按钮来实现UITableViewCell选择的效果?

Ios 如何通过单击UITableViewCell中的按钮来实现UITableViewCell选择的效果?,ios,objective-c,uitableview,singleton,Ios,Objective C,Uitableview,Singleton,我在列表视图控制器中有一个菜单视图。录制单元格中的“更多”按钮时,在UITableViewCell上添加的菜单视图 使用单例很容易实现。以下是代码: @implementation ProductsOperationMenu static ProductsOperationMenu *_instance; + (instancetype)sharedInstance{ static dispatch_once_t onceToken; dispatch_once(&o

我在列表视图控制器中有一个菜单视图。录制单元格中的“更多”按钮时,在UITableViewCell上添加的菜单视图

使用单例很容易实现。以下是代码:

@implementation ProductsOperationMenu
static ProductsOperationMenu *_instance;
+ (instancetype)sharedInstance{

    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [[self alloc] initWithFrame:CGRectZero];
    });
    return _instance;
}


- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setup];
    }
    return self;
}
ZBMyProductsCell.m

@implementation ZBMyProductsCell

- (void)awakeFromNib
{
    [super awakeFromNib];
    _operationMenu = [[ProductsOperationMenu alloc] initWithFrame: CGRectZero];
}

- (IBAction)operationButtonClick:(UIButton *)sender {
    if ([self.contentView.subviews containsObject:_operationMenu]) {
        _operationMenu.hidden = ![_operationMenu isHidden];
    } else{
        [self.contentView addSubview:_operationMenu];
        _operationMenu.hidden = NO;
    }

    [_operationMenu mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(205);
        make.height.mas_equalTo(60);
        make.bottom.mas_equalTo(self.operationButton).offset(0);
        make.right.mas_equalTo(self.operationButton.mas_left).offset(-10);
    }];
}
我认为这是独生子女虐待。我想改进代码

没有singleton,代码和效果:

@implementation ProductsOperationMenu
- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setup];
    }
    return self;
}

我想我必须处理手机间的信息发送。单击一个单元格的按钮时,其他单元格的菜单视图必须隐藏

我认为这与细胞的选择非常相似。选择一个单元格时,上一个选定单元格的效果将被取消

无或一个


那么,如何通过单击UITableViewCell中的一个按钮来实现UITableViewCell选择的效果呢?

生成一个全局整数,其中包含当前被单击单元格的索引,当单击单元格中的任何按钮时,更改索引并重新加载tableView——在cellForRow中

 if(indexpath.row == index)
 {

    cell.menuView.isHidden = false
 }
 else
 {

    cell.menuView.isHidden = true
 }
编辑:


如果要在选择另一个菜单视图时设置菜单视图隐藏的动画,则必须将tableview设置为全局并访问其可见单元格,并在持续时间内设置菜单视图的alpha动画

事实上,我正在寻找类似于系统效果的解决方案。是否要在选择新菜单视图时设置其他菜单视图隐藏的动画?而不是动画。按照你的计划,我必须重新加载tableView。所以每次点击,视图都会闪烁,闪烁。。。它很重,对用户不友好。你的计划是非常直观的,不是appleSee编辑,你只需要重新加载可见的单元格,这是在菜单中隐藏菜单视图的唯一方法
func重载行(位于:[indepath],with:UITableViewRowAnimation)
我认为苹果在UITableViewCell类中做了一些事情,我不知道。我想知道为什么在选择一个单元格时,前一个选定单元格的效果会消失。