ios编程 - 格式字符串不使用的数据参数 [英] ios programming - Data argument not used by format string

查看:416
本文介绍了ios编程 - 格式字符串不使用的数据参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行以下代码时,我得到格式字符串时未使用的数据参数错误:

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"]);

}

我在上都收到错误NSLog 行。另外,这是日志所说的:

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 =

谢谢,
Arthur

Thank you, Arthur

推荐答案

NSLog(@"NSString = ", colour);    
NSLog(@"NSUserDefaults =", [defaults objectForKey:@"colour"]);

有问题

应该是

NSLog(@"NSString = %@", colour);
NSLog(@"NSUserDefaults = %@", [defaults objectForKey:@"colour"]);

本例中的格式说明符是%@ 用于打印对象。要打印数字,您可以使用%d 之类的内容。 请参阅此处的完整文档。

The format specifier in this case is the %@ which is used to print an object. To print numbers you'd use something like %d. See complete documentation here.

这篇关于ios编程 - 格式字符串不使用的数据参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆