Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i pass an int value through a selector method?

I want to pass an int value from my selector method, but the selector method takes only an object type parameter.

int y =0;
[self performselector:@selector(tabledata:) withObject:y afterDelay:0.1];

Method execution is here

-(int)tabledata:(int)cellnumber {
   NSLog(@"cellnumber: %@",cellnumber);
   idLabel.text = [NSString stringWithFormat:@"Order Id: %@",[[records objectAtIndex:cellnumber] objectAtIndex:0]];
}

but I am not getting exact integer value in my method, I am only getting the id value.

like image 543
Emon Avatar asked Oct 26 '11 06:10

Emon


People also ask

What is selector method?

A selector is an identifier which represents the name of a method. It is not related to any specific class or method, and can be used to describe a method of any class, whether it is a class or instance method. Simply, a selector is like a key in a dictionary.

How do you call a selector in Swift?

The solution to your problem is to pass the object that should run the selector method along with the selector to the initialisation of the ValueAnimator object. Also update the timerCallback() : @objc func timerCallback() { ... _ = target.


2 Answers

The easiest solution, if you 'own' the target selector, is to wrap the int argument in an NSNumber:

-(int)tabledata:(NSNumber *)_cellnumber {
    int cellnumber = [_cellnumber intValue];
    ....
}

To call this method you would use:

[self performselector:@selector(tabledata:) withObject:[NSNumber numberWithInt:y] afterDelay:0.1];
like image 167
Aderstedt Avatar answered Oct 13 '22 00:10

Aderstedt


Instead of your performSelector:withObject:afterDelay:, use an NSTimer, thusly:

int y = 0;
[NSTimer scheduledTimerWithTimeInterval:0.1 repeats:NO block:^(NSTimer *timer) {
    [self tabledata:y];
}];

You can pass whatever you want in the timer block.

like image 23
Jeff Avatar answered Oct 13 '22 00:10

Jeff