I am trying to do animation. At some point I want to execute a method through NSTimer. I need to pass in 1 argument. This I do it through userInfo in NSTimer. In the selector method I am trying to access back this passed arg. But when I actually run this I get the following exception. It says invalid argument. What am I doing wrong?
“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;
}
You have passed the wrong selector.
It should be,
That said you should consider sending the index path of the table view cell rather than the cell itself as cells are reused. You can get the cell later using
cellForRowAtIndexPath:method the table view in thehideCellView:method.If you are looking to set a delay in the animation then use the
setAnimationDelay:method rather that usingNSTimer.