美文网首页iOS实战开发
iOS-UIbutton无法替换监听方法另辟他径

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

作者: 暖游丶 | 来源:发表于2016-06-20 14:31 被阅读64次

    示范:

        方法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无法替换监听方法另辟他径

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