我有点困惑为什么我收到错误“格式字符串未使用数据参数”
有其他人在 iOS6 的 Xcode 4.5 中得到这个或修复这个问题吗?
- (IBAction)facebookPost:(id)sender
{
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
mySLComposerSheet = [[SLComposeViewController alloc] init];
mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[mySLComposerSheet setInitialText:[NSString stringWithFormat:@"I'm listening to Boilerroom Recordings via the Boilerroom iPhone Application",mySLComposerSheet.serviceType]];
[mySLComposerSheet addImage:[UIImage imageNamed:@"BOILERROOM_LOGO_250x250.png"]];
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
}
[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
NSLog(@"dfsdf");
switch (result) {
case SLComposeViewControllerResultCancelled:
break;
case SLComposeViewControllerResultDone:
break;
default:
break;
}
}];
}
您遇到的错误是不言自明的:当您使用stringWithFormat
,您应该在格式字符串中提供一些格式占位符(例如%@
作为对象的占位符,%d
对于整数,%f
作为浮点数的占位符等,就像在所有类似 printf 的方法中一样)。
但你一个也不用。所以论证mySLComposerSheet.serviceType
您放在格式字符串后面的格式字符串不使用格式字符串(无占位符),并且在这里没有用。因此,错误说“数据参数(即mySLComposerSheet.serviceType
) 不被格式字符串使用”。
因此,解决方案取决于您打算做什么:
-
如果你确实想插入serviceType
在字符串中的某个位置,只需添加一个%@
(as serviceType
is an NSString*
,因此是一个对象)占位符在格式字符串中,位于您的值的位置mySLComposerSheet.serviceType
被插入。例如:
[mySLComposerSheet setInitialText:[NSString stringWithFormat:@"I'm listening to Boilerroom Recordings via the Boilerroom iPhone Application and want to share it using %@ !",mySLComposerSheet.serviceType]];
-
但我想事实上你不想插入serviceType
值在你的initialText字符串中的任何地方(我想知道为什么你首先添加这个参数)。在这种情况下,您可以简单地删除调用中这个无用的附加参数stringWithFormat:
。或更好,因为那时你的stringWithFormat
调用不会有任何格式占位符 like %@
总而言之,这是完全没用stringWithFormat
anyway, so 只需直接使用字符串文字即可!
[mySLComposerSheet setInitialText:@"I'm listening to Boilerroom Recordings via the Boilerroom iPhone Application"];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)