2011-01-26 79 views
0

我真的新手开发iPhone应用程序,我有一个问题...需要帮助的功能参数iPhone SDK

我想知道我该怎么办呢接收VAR,我的函数返回。

请看:

-(void)myfunc{ 
    float num1 = 2.50; 
    float num2 = 3.50; 

    //here is my doubt, how can I get the value that function returns? 
    float varreceived = [self getNumber:num1:num2]; 
} 

//the function that receive the vars and returns a value 

-(float)getNumber: (float)var1 :(float)var2 { 

     NSLog(@"1->%f",var1); 
     NSLog(@"2->%f",var2); 

     return 3.23; 
} 

当我建立我收到此错误:

“错误:不被忽略,因为它应该是空值”

在这一行

float varreceived = [self getNumber:num1:num2];

更新:

NOP,我收到此错误,当我建:

float varreceived = [self getNumber:num1:num2]; 

最大:

then you probably declared the -(float)getNumber: (float)var1 :(float)var2 as -(void)getNumber: (float)var1 :(float)var2 in your header

"error: void value not ignored as it ought to be"

在这一行个

HispaJavi:

Yeah!! this is the problem, I wrote "-(void)getNumber" in header! I changed it "-(float)getNumber" and it works!! thanks!!

+0

你的代码看起来很好。你可以在设置好后记录varRecieved的值,以便我们看到它会发生什么? – 2011-01-26 12:35:47

+0

看,我编辑它,当我建立时,我收到一个错误... – HispaJavi 2011-01-26 12:40:01

回答

0

一切都OK。你会收到3.23