button 移除target

 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)