是什么导致下面第 3 行出现“预期标识符”错误?
-(IBAction)changeGreeting:(id)sender {
self.userName = self.textField.text;
float amount = [[self.textField.text] floatValue]; **! Expected identifier**
// float amount = [[self.userName] floatValue];
NSString *nameString = self.userName;
if ([nameString length] == 0) {
nameString = @"World";
}
NSString *greeting = [[NSString alloc] initWithFormat:@"Hello, %@!", nameString];
self.label.text = greeting;
}
我可以将文本转换为浮点数、将值加倍并在同一个按钮操作方法中显示吗?
我是 OOP 编程的新手。非常感谢任何提示。沃尔特