将float变量作为参数传递 [英] passing float variable as parameter
本文介绍了将float变量作为参数传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试编写一个带有float参数的方法,并使用performselector调用它,但是这样做却出错了.以下是我的代码:
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:
[发送器performSelector:带有对象的选择器:进度/总计];
[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 {
}
推荐答案
您需要传递一个真实的对象,而不是int或float这类基本类型之一.
You need to pass a real object, not one of the basic types like int or float.
将其包装为NSNumber
对象:
[sender performSelector:selector withObject:[NSNumber numberWithFloat:progress/total]];
-(void) updateProgress:(NSNumber *)aProgress {
float fProgress = [aProgress floatValue];
}
这篇关于将float变量作为参数传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文