-1

我正在开发一个应用程序,我将在其中调用一个方法,并传入参数 an NSTimeInterval。我的方法是这样声明的:

-(void)MethodwithTime:(NSTimeInterval)t
{
    NSLog(@"Test, T = %f", t);
    ...
}

我这样称呼它UIViewController

[myObject performSelector:@selector(MethodwithTime:) withObject:[NSNumber numberWithDouble:t]];

因为我读到那NSTimeInterval是双重的。但是NSLog测试给了我一些零……测试,T = 0.000000

我该如何解决?

谢谢 !

4

1 回答 1

3

NSTimeInterval不是对象(它是某些浮点数类型的 typedef,但如果您阅读过它的文档,您可能会知道)。因此,当您尝试将指针(Objective-C 对象由其表示)解释为浮点原语时,您会得到意想不到的结果。改变 to 参数的类型怎么MethodwithTime:NSNumber *

(哦,方法名称以小写字母开头并使用camelCaps,所以MethodwithName:不是惯用的,MethodWithName:也不好,methodWithName:是。)

于 2013-07-08T00:01:02.240 回答