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

释放双眼,带上耳机,听听看~!
@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文章

iOS xib控件变成框框 An internal error occurred 报错

2019-12-4 19:15:42

iOS文章

iOS UIViewController 生命周期 APPDelegate 生命周期

2019-12-5 10:33:03

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索