ios编程-格式字符串未使用数据参数
当我运行以下代码时,我收到 Data argument not use by format string
错误:
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
NSString *colour = ([colourArray objectAtIndex:row]);
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:(colour) forKey:@"colour"];
NSLog(@"NSString =", colour);
NSLog(@"NSUserDefaults =", [defaults objectForKey:@"colour"]);
}
我在两行 NSLog
行上都收到错误。另外,日志内容如下:
2011-10-25 09:01:50.260 Random[35636:b303] NSString =
2011-10-25 09:01:50.260 Random[35636:b303] NSUserDefaults =
谢谢, 亚瑟
I get a Data argument not used by format string
error when I run the following code:
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
NSString *colour = ([colourArray objectAtIndex:row]);
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:(colour) forKey:@"colour"];
NSLog(@"NSString =", colour);
NSLog(@"NSUserDefaults =", [defaults objectForKey:@"colour"]);
}
I get the error on both NSLog
lines. Also, here is what the log says:
2011-10-25 09:01:50.260 Random[35636:b303] NSString =
2011-10-25 09:01:50.260 Random[35636:b303] NSUserDefaults =
Thank you,
Arthur
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有问题
应该是
本例中的格式说明符是用于打印
对象
的%@
。要打印数字,您可以使用类似%d
的内容。 在此处查看完整文档。Is problematic
Should be
The format specifier in this case is the
%@
which is used to print anobject
. To print numbers you'd use something like%d
. See complete documentation here.@debuggerman 的回答绝对正确。但是,如果您使用
[defaults setObject:colour forKey:@"colour"];
而不是[defaults setObject:(colour) forKey:@"colour"];< /code>
请注意,我删除了对象
颜色
的括号。Answer from @debuggerman is absolutely correct. But you can improve your code if you use
[defaults setObject:colour forKey:@"colour”];
instead of[defaults setObject:(colour) forKey:@"colour"];
Note that I removed the parentheses for object
colour
.