UITextField“预期标识符”问题

问题描述:

我是新来obj-c,我试图编写一个简单的“输入到plist”应用程序。我有两个输入:UITextField“预期标识符”问题

@property (strong, nonatomic) IBOutlet UITextField *costo; 
@property (strong, nonatomic) IBOutlet UITextField *descrizione; 

,我将它们合成在.m文件

@synthesize costo; 
@synthesize descrizione; 

然后我有一个函数SAVEDATA()有:

NSNumber *newValue = [NSNumber numberWithInt:[costo.text intValue]]; 
[mutableDictCopy setObject:newValue forKey:[descrizione.text]]; 

此功能工作正常costo.text,但后来我收到一个“预期标识符”错误descrizione.text。如果我用@“foo”切换它,一切都很顺利,它会更新我的plist。我在哪里得到错误?

您正在混合成员和消息语法。这是好的:

[descrizione text] 

以下情况也行。它意味着同样的事情。

descrizione.text 

这是不正常:

[descrizione.text] 
+0

**哎呀!** d TY队友 – 2012-07-23 12:49:22

使用此

[mutableDictCopy setObject:newValue forKey:descrizione.text]; 

,而不是

[mutableDictCopy setObject:newValue forKey:[descrizione.text]];