美文网首页
iOS 按钮连续点击 最后才一次提交

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

作者: 赵哥窟 | 来源:发表于2018-11-12 16:54 被阅读21次
@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 { 
[self.timer invalidate]; 
self.timer = nil; 
self.timer =[NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(requestData) userInfo:nil repeats:NO]; 
[[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes]; 
} 

- (void)requestData{ 
NSLog(@"我请求数据啦"); 
} 

相关文章

网友评论

      本文标题:iOS 按钮连续点击 最后才一次提交

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