我試圖從這個問題再現例如:Objective-C的實現和調用方法
How to create a method in Objective-C that takes a NSString stringWithFormat as a parameter?
而且我在@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]);
}
這個例子有什麼問題?
你應該回去閱讀一個基本的Objective-C教程。 – 2013-09-16 18:25:02
我還在讀書,在試圖提出這個問題之前,我單獨失去了幾個小時,現在這個問題已經非常明顯 - 但是以新語言開始的人會遇到同樣的困難 –