iOS-UIbutton无法替换监听方法另辟他径

示范:

    方法1:   [self.Uploadexamine addTarget:self action:@selector(btnlinkS:) forControlEvents:UIControlEventTouchUpInside];

     方法2: [self.Uploadexamine addTarget:self action:@selector(btnlinkTwo:) forControlEvents:UIControlEventTouchUpInside];

这里btnlinkTwo:  是无法替换掉btnlinkS的监听方法的,重复写只是增加监听方法

采用Button的监听同一个方法在同一个方法里进行判断
1.取得 Button -Uploadexamin的标题内容进行比较

-(void)isOKStringComent {
    
    NSString *commetext = self.Uploadexamine.titleLabel.text;
    
    if([commetext isEqualToString:@"提交审核"]){
        [self.Uploadexamine addTarget:self action:@selector(btnlinkS:) forControlEvents:UIControlEventTouchUpInside];
      
    }if ([commetext isEqualToString:@"修改资料"] && self.icotype == 1) {
         [self.Uploadexamine addTarget:self action:@selector(btnlinkS:) forControlEvents:UIControlEventTouchUpInside];
    }else  {
    
    [self.Uploadexamine addTarget:self action:@selector(btnlinkS:) forControlEvents:UIControlEventTouchUpInside];
    }
   
 
}

2.进行判断

-(void)btnlinkS:(UIButton *)btn{
    
    NSString *strBtn = btn.titleLabel.text;
    if ([strBtn isEqualToString:@"提交审核"]) {
        [self Submitaudit];
        
    }else if ([strBtn isEqualToString:@"修改资料"] && self.icotype == 1){
        
        [self showHUDErrorWithStatus:@"审核中不可修改资料!"];
       
    }else if ([strBtn isEqualToString:@"修改资料"] && self.icotype == 2){
        
        [self pushUoloadVC];
    }else if ([strBtn isEqualToString:@"修改资料"] && self.icotype == 3){
        
         [self pushUoloadVC];
        
    }
    
}

你可能感兴趣的:(iOS-UIbutton无法替换监听方法另辟他径)