mySLComposerSheet上的格式字符串未使用ERROR数据参数 [英] ERROR data argument not used by format string on mySLComposerSheet

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

问题描述

我有点困惑为什么我得到的格式字符串没有使用ERROR'数据参数'

I'm a bit confused at why I'm getting the ERROR 'data argument not used by format string'

有没有其他人得到这个或修复了这个X6 4.5 for iOS6?

Has anybody else got this or fixed this in Xcode 4.5 for iOS6?

- (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的方法一样。)

The error you have is quite self-explainatory: as you use stringWithFormat, you are supposed to provide some formatting placeholder in your format string (like %@ as a placeholder for a object, %d for integers, %f as a placeholder of a float, etc, like in all printf-like methods).

但你不使用任何方法。所以你在格式字符串之后放置的参数 mySLComposerSheet.serviceType 没有被格式字符串(没有占位符)使用,在这里没用。因此,错误说数据参数(即 mySLComposerSheet.serviceType )未被格式字符串使用。

But you don't use any. So the argument mySLComposerSheet.serviceType you put after the format string is not used by the format string (no placeholder) and is useless here. Thus the error saying that "the data argument (namely mySLComposerSheet.serviceType) is not used by the format string".

所以解决方案取决于你打算做什么:

So the solution depending on what you intend to do:


  • 如果你真的想在你的字符串中的某处插入 serviceType ,只需添加一个%@ (作为 serviceType 是一个 NSString * ,因此是一个对象)占位符在你的格式字符串中,位于你的值要插入的mySLComposerSheet.serviceType 。例如:

  • If you really want to insert the serviceType somewhere in your string, simply add a %@ (as serviceType is an NSString*, thus an object) placeholder in your format string, at the position you what the value of mySLComposerSheet.serviceType to be inserted. For example:

[mySLComposerSheet setInitialText:[NSString stringWithFormat:@"I'm listening to Boilerroom Recordings via the Boilerroom iPhone Application and want to share it using %@ !",mySLComposerSheet.serviceType]];


  • 但我猜你实际上不想插入 serviceType value在initialText字符串中的任何位置(我想知道为什么你在第一个地方添加了这个参数)。在这种情况下,您可以简单地删除对 stringWithFormat:的调用的这个无用的附加参数。或者更好,因为此时您的 stringWithFormat 调用将没有任何格式占位符,如%@ 完全无用,无论如何 stringWithFormat ,所以只需直接使用字符串文字

  • But I guess that in fact you don't want to insert the serviceType value anywhere in your initialText string (I wonder why you added this argument at the first place). In that case, you can simply remove this useless additional argument of your call to stringWithFormat:. Or better, because at that point your stringWithFormat call won't have any format placeholder like %@ at all, this is totally useless to use stringWithFormat anyway, so simply use the string literal directly!

    [mySLComposerSheet setInitialText:@"I'm listening to Boilerroom Recordings via the Boilerroom iPhone Application"];
    


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

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