0

我正在尝试在NSLog()消息中返回“totaal”的值。如果我把所有代码都放在- (IBAction)txtChangeEinde:(id)sender它工作正常,我只是想弄清楚这些方法和类是如何工作的。

@implementation Oak
@synthesize txtEinde,txtBegin,cboSchaal;

- (float)berekenTotaal:(float) totaal{
  begin = [txtEinde floatValue];
  einde = [txtBegin floatValue];
  if (begin<0) {
    begin= begin*-1;
  }
  totaal = begin + einde;



  return totaal;

}
  - (IBAction)txtChangeEinde:(id)sender {
    //where it goes wrong!
    NSLog(@"totaal: %.2f",[berekenTotaal totaal]);


}

示例代码(图片)

4

1 回答 1

0

像这样打电话,

- (IBAction)txtChangeEinde:(id)sender {

    NSLog(@"totaal: %.2f",[self berekenTotaal:totaal]);   OR

    NSLog(@"totaal: %.2f",[self berekenTotaal:someFloatValue]);


}
于 2013-07-19T04:29:35.567 回答