1.UIButton的点击优化(防止用户吃饱了没事干猛点按钮)
- (void)starButtonClickedBack:(id)sender
{
NSLog(@"我没有优化按钮点击");
//先将未到时间执行前的任务取消
[[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(back) object:sender];
[self performSelector:@selector(back) withObject:sender afterDelay:1.0f];
}
-(void)back{
NSLog(@"我点击的按钮");
}
2.数据加载(线程)
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// 耗时的操作
dispatch_async(dispatch_get_main_queue(), ^{
// 更新界面
});
});
时间: 2024-10-27 04:14:06