您的位置:首页 > 移动开发 > IOS开发

[10秒学会] - iOS 按钮连续点击 最后才一次提交

2016-05-28 18:58 459 查看
摘要: [10秒学会] - iOS 按钮连续点击 最后才一次提交

按钮连续点击最后一次才 才响应提交

直接上代码吧 很简单

额外知识点:这里是用不到的

[self.timer setFireDate:[NSDate distantFuture]];

[self.timer setFireDate:[NSDate distantPast]];

定时器的开启与关闭

[code=language-objectivec]//
//  ViewController.m
//  cartBtnDemo
//
//  Created by point on 16/5/26.
//  Copyright © 2016年 tshiny. All rights reserved.
//

#import "ViewController.h"

static int shopNUm=0;

@interface ViewController ()
@property (nonatomic, strong) NSTimer *timer;//定时器
@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
UIButton *btn = [[UIButton alloc]init];
[btn setTitle:@"赵大财" forState:UIControlStateNormal];
[self.view addSubview:btn];
btn.frame=CGRectMake(100, 100, 100, 100);
btn.backgroundColor = [UIColor grayColor];
[btn addTarget:self action:@selector(Click:) forControlEvents:UIControlEventTouchUpInside];
[btn setTitleColor:[UIColor blueColor] forState:UIControlStateHighlighted];
[btn setTitleColor:[UIColor yellowColor] forState:UIControlStateNormal];
}

- (void)Click:(UIButton *)btn {
shopNUm++;
[self.timer invalidate];
self.timer = nil;
self.timer =[NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(updateTimer) userInfo:nil repeats:NO];
[[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];

}

- (void)updateTimer{
NSLog(@"我请求数据啦  我的加入的数据是%d",shopNUm);
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息