tags:

views:

33

answers:

2

Hi,

I am trying to write a method with float parameter and call it using performselector but i am getting error in doing this. Following is my code:

[sender performSelector:selector withObject:progress/total];

here progress and total both are float variabal.

I am trying to call following method in different class

-(void) updateProgress:(float)fl {

}

+5  A: 

You need to pass a real object, not one of the basic types like int or float.

Wrap it into an NSNumber object:

[sender performSelector:selector withObject:[NSNumber numberWithFloat:progress/total]];

-(void) updateProgress:(NSNumber *)aProgress {
   float fProgress = [aProgress floatValue];
}
Eiko
this is also right and u can try this also[sender performSelector:selector withObject:(float)(progress/total)];
GhostRider
@GhostRider: No. A float is something completely different as an NSObject.
Eiko
sorry then you can save it in one string and then pass that string in object and then convert it, your way is also good but me never try this with nsnumber me always save in string and pick [string floatValue] when need
GhostRider
You can encode anything in a string, it just doesn't make sense and can easily lose precision.
Eiko
thanks eiko went with your suggestion.
pankaj
A: 

It's because -performSelector:withObject: only works for Objective-C objects. float isn't one of these.

Why not just use

[(TheClass*)sender updateProgress:progress/total];

?

KennyTM
The naming of the variable makes me think he wants to update UI from a background thread which makes calling on the main thread mandatory.
Eiko
Perhaps he is trying to use -performSelector:withObject:afterDelay
h4xxr
u r correct Eiko, this is what i exactly wanted to do, thanks
pankaj