美文网首页
button 移除target

button 移除target

作者: 寒雨晚风 | 来源:发表于2022-02-10 16:41 被阅读0次

     UIView*view=  self.navigationItem.leftBarButtonItem.customView;

        if([viewisKindOfClass:[UIButtonclass]]) {

            UIButton*btn =(UIButton*)view;

            NSSet*targets = [btnallTargets];//或者使用btn. allTargets获取

            NSEnumerator*enumerator = [targetsobjectEnumerator];

            NSObject*obj =nil;

            while(obj = [enumeratornextObject])

            [btnremoveTarget: obj action: @selector(close) forControlEvents: UIControlEventTouchUpInside];//注意:这里要跟addTarget写法一致

            [btnaddTarget:self action:@selector(lastPress ) forControlEvents:UIControlEventTouchUpInside];

        }

    相关文章

      网友评论

          本文标题:button 移除target

          本文链接:https://www.haomeiwen.com/subject/daankrtx.html