[10秒学会] - iOS 按钮连续点击 最后才一次提交
2016-05-28 18:58
459 查看
摘要: [10秒学会] - iOS 按钮连续点击 最后才一次提交
按钮连续点击最后一次才 才响应提交
直接上代码吧 很简单
额外知识点:这里是用不到的
[self.timer setFireDate:[NSDate distantFuture]];
[self.timer setFireDate:[NSDate distantPast]];
定时器的开启与关闭
按钮连续点击最后一次才 才响应提交
直接上代码吧 很简单
额外知识点:这里是用不到的
[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
相关文章推荐
- 解决 NSObjCRuntime的问题
- 去除tabBar的上横线和navigationBar的下横线方法介绍
- iOS学习- 03 控件
- iOS-OC中的lazyLoad(懒加载)
- 调用系统相机和系统相册,并保存到沙盒中
- iOS中在oc中制作一个霓虹灯
- opencv-ios开发笔记6 利用canny简单提取轮廓
- 【原】iOS学习之第三方-AFNetworking1.3.0
- iOS-单例模式
- iOS应用发布流程详解
- iOS searchbar textfield placeholder color
- iOS itunesconnect 权限分配
- 一文让你彻底了解iOS字体相关知识
- ios jsonModel解析数组
- Nagios
- iOS-OC中的静态方法(类方法)与实例方法
- IOS- 开发证书与发布证书申请和安装步骤
- iOS-OC中的类与对象
- iOS一个全屏滑动返回手势
- iOS中QQ登录界面的制作,登录页面和注册页面的切换