我试图从这个问题中重现一个例子:
如何在 Objective-C 中创建一个以 NSString stringWithFormat 作为参数的方法?
我在@interface 中创建了:
- (float)strToFloat:(NSString *)str;
在@implementation 中:
- (float)strToFloat:(NSString *)str {
str = [str stringByReplacingOccurrencesOfString:@"."
withString:@""];
str = [str stringByReplacingOccurrencesOfString:@","
withString:@"."];
return [str floatValue];
}
毕竟,当我尝试编译应用程序时,我收到了这个错误:Use of undeclared identifier 'strToFloat'
在这个方法中:
- (IBAction)addItem:(id)sender {
NSLog(@"float value is: %.2f", [strToFloat labelPrice.text]);
}
这个例子有什么问题?