UITextField "Expected identifier"问题



我是obj-c的新手,我正在尝试编写一个简单的"inputs to plist"应用程序。我有两个输入:

@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。我哪里错了?

使用此

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

而不是

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

您正在混合成员语法和消息语法。这没问题:

[descrizione text]

下面也可以。意思是一样的。

descrizione.text

这不好:

[descrizione.text]

最新更新