gpt4 book ai didi

ios - NSTImer & 通过选择器发送参数

转载 作者:行者123 更新时间:2023-11-28 23:15:39 25 4
gpt4 key购买 nike

我正在尝试制作动画。在某些时候,我想通过 NSTimer 执行一个方法。我需要传入 1 个参数。这是我通过 NSTimer 中的 userInfo 完成的。在选择器方法中,我试图访问回这个传递的 arg。但是当我实际运行它时,我得到以下异常。它说无效的论点。我做错了什么?

"Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FLOViewController hideCellView]: unrecognized selector sent to instance 0x1681d0'"

-(void)hideCellView:(NSTimer *)timer
{
UITableViewCell *cellView = (UITableViewCell *)[timer userInfo];
[cellView addSubview:self.extrasView];
return;
}

-(IBAction)showExtras:(id)sender
{
if(![sender isKindOfClass: [UIButton class]]) return; // be paranoid
self.searchResTable.scrollEnabled = NO;

//Get the exact cell where the click happened
UIButton *button = sender;
CGPoint correctedPoint = [button convertPoint:button.bounds.origin toView:self.searchResTable];
NSIndexPath *indexPath = [self.searchResTable indexPathForRowAtPoint:correctedPoint];
UITableViewCell *cellView = [self.searchResTable cellForRowAtIndexPath:indexPath];

//now run animation
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
forView:cellView
cache:YES];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDuration:1];
[NSTimer scheduledTimerWithTimeInterval:0.5
target:self
selector:@selector(hideCellView)
userInfo:cellView
repeats:NO];
[UIView commitAnimations];
return;
}

最佳答案

您传递了错误的选择器。

selector:@selector(hideCellView) 

应该是,

selector:@selector(hideCellView:) 

也就是说,您应该考虑发送表格 View 单元格的索引路径而不是单元格本身,因为单元格会被重用。您可以稍后使用 cellForRowAtIndexPath: 方法在 hideCellView: 方法中的 TableView 中获取单元格。

如果您希望在动画中设置延迟,请使用 setAnimationDelay: 方法而不是使用 NSTimer

关于ios - NSTImer & 通过选择器发送参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6578576/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com