方法一
1.首先定义一个BOOL类型来判断是否点击了第一次:
@property (nonatomic, assign) BOOL isSelect;
2.然后在点击事件中这样写:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//防止重复点击
if (self.isSelect == false) {
self.isSelect = true;
//在延时方法中将isSelect更改为false
[self performSelector:@selector(repeatDelay) withObject:nil afterDelay:0.5f];
// TODO:在下面实现点击cell需要实现的逻辑就可以了
}
3.延时
- (void)repeatDelay{
self.isSelect = false;
}
方法二
1.宏定义:
// 防止多次调用
#define kPreventRepeatClickTime(_seconds_) \
static BOOL shouldPrevent; \
if (shouldPrevent) return; \
shouldPrevent = YES; \
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)((_seconds_) * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ \
shouldPrevent = NO; \
}); \
2.在所需要的button或者cell的action前调用即可:
kPreventRepeatClickTime(0.5);
本文介绍两种防止iOS TableViewCell重复点击的方法。方法一:使用BOOL变量和延时方法实现。方法二:通过宏定义和GCD延时执行来防止重复点击。适用于iOS应用开发中避免TableView响应过快导致的用户体验问题。
3187

被折叠的 条评论
为什么被折叠?



