如何解决如何在LongPressGesture Objective-C龙头中重置/重启NSTimer
我在长按手势时对NSTimer有小的问题。如何使任何计时器的计时器无效?如果我长按了此计时器,则从任何按下的单元格开始计时。例如,我长按3个单元,使计时器工作3次。
我不知道。这是下面的代码,经过一段时间后我尝试给出条件,但现在hideButtonTimer
不算在内。
我有NSTimer声明为:
NSTimer *hideButtonTimer;
我的设置手势识别器:
- (void)setupGestureRecognizersForTableView {
UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
[lpgr setMinimumPressDuration:1.0];
[lpgr setDelegate:self];
[self.tableView addGestureRecognizer:lpgr]; }
和功能handleLongPress
- (void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer {
CGPoint p = [gestureRecognizer locationInView:self.tableView];
selectedIndexPath = [self.tableView indexPathForRowAtPoint:p];
if (selectedIndexPath != nil && gestureRecognizer.state == UIGestureRecognizerStateBegan) {
[self.tableView reloadData];
[self resetTableView];
hideButtonTimer = nil;
PresentationCell *cell = (PresentationCell *)[self.tableView cellForRowAtIndexPath:selectedIndexPath];
NSLog(@"start click");
[cell.deleteButton setHidden:NO];
[cell.updateShowView setHidden:YES];
if (IS_IPAD) {
[cell.nameLabel setHidden:NO];
[cell.descriptionLabel setHidden:NO];
} else {
[cell.nameLabel setHidden:YES];
[cell.descriptionLabel setHidden:YES];
};
if (hideButtonTimer == nil) {
hideButtonTimer = [NSTimer scheduledTimerWithTimeInterval:5.0f target:self selector:@selector(hideButton) userInfo:nil repeats:NO];
}
[hideButtonTimer invalidate];
hideButtonTimer = nil;
//NSLog(@"%@",hideButtonTimer);
}
}
和倒数第二个函数hideButton:
- (void)hideButton {
NSLog(@"hide!");
PresentationCell *cell = (PresentationCell *)[_tableView cellForRowAtIndexPath:selectedIndexPath];
cell.deleteButton.hidden = YES;
cell.nameLabel.hidden = NO;
cell.descriptionLabel.hidden = NO;
// [hideButtonTimer invalidate];
// hideButtonTimer = nil;
}
请帮助。我将非常感谢。
解决方法
编辑
好吧,我已根据我的了解对它进行了一些更改。只要有轻拍,计时器就会重置,但仍然只会触发一次。希望这就是你想要的。
尝试以下操作。
- 添加ivar
class OrderFilter(django_filters.FilterSet):
class Meta:
model = Order
fields = '__all__'
exclude = ['customer','date_created']
def __init__(self,*args,**kwargs):
super(OrderFilter,self).__init__(*args,**kwargs)
self.filters['note'].extra.update(
{'empty_label': 'Note'})
- 更改hideButton(删除那些已注释掉的内容)
@property (nonatomic) BOOL pressed;
- 长按,在计时器倒计时时看到轻拍时重置计时器
- (void)hideButton {
NSLog(@"hide!");
PresentationCell *cell = (PresentationCell *)[_tableView cellForRowAtIndexPath:selectedIndexPath];
cell.deleteButton.hidden = YES;
cell.nameLabel.hidden = NO;
cell.descriptionLabel.hidden = NO;
[hideButtonTimer invalidate];
hideButtonTimer = nil;
}
因此,您使用ivar来记住新闻,而不是计时器本身。
PS:这可能不完全是您想要的,但是使用ivar和计时器来获取您想要的东西。
PSS:计时器-不清楚代码中的内容,但可能也应该是一个ivar吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。