美文网首页iOS开发
iOS设置按钮不可点击并倒计时方法

iOS设置按钮不可点击并倒计时方法

作者: JasonEVA | 来源:发表于2016-03-07 10:33 被阅读2529次

    - (void)registerClicked

    {

    //设置计时器

    self.secondsCoundDown = 60;

    self.countDownTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeFireMethod) userInfo:nil repeats:YES];

    //设置按钮不可点击

    [self.resentButton setEnabled:NO];

    //发出网络请求

    RegisterRequestDAL *registerDAL = [RegisterRequestDAL new];

    registerDAL.email = self.emailAddress;

    registerDAL.password = self.password;

    [registerDAL requestWithDelegate:self];

    [SVProgressHUD show];

    }

    //倒计时方法,

    - (void)timeFireMethod

    {

    self.secondsCoundDown --;

    //更新按钮倒计时时间

    self.time = [NSMutableString stringWithFormat:@"(%lds)Resend validation messages",(long)self.secondsCoundDown];

    [self.resentButton setTitle:self.time forState:UIControlStateDisabled];

    if (self.secondsCoundDown == 0) {

    [self.countDownTimer invalidate];

    self.countDownTimer = nil;

    //设置按钮可点击

    [self.resentButton setEnabled:YES];

    [self.resentButton setTitle:@"Resend validation messages" forState:UIControlStateDisabled];

    }

    NSLog(@"%ld",(long)self.secondsCoundDown);

    }

    相关文章

      网友评论

        本文标题:iOS设置按钮不可点击并倒计时方法

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