【问题标题】:ERROR data argument not used by format string on mySLComposerSheetmySLComposerSheet 上的格式字符串未使用错误数据参数
【发布时间】:2012-09-27 12:29:55
【问题描述】:

我对为什么会收到错误“格式字符串未使用的数据参数”感到有些困惑

有没有其他人在 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;
    }
}];

}

【问题讨论】:

    标签: iphone xcode ios6 xcode4.5


    【解决方案1】:

    您遇到的错误是不言自明的:当您使用stringWithFormat 时,您应该在格式字符串中提供一些格式化占位符(例如%@ 作为对象的占位符,%d 用于整数, %f 作为浮点数的占位符等,就像在所有类似 printf 的方法中一样)。

    但你不使用任何东西。因此,您在格式字符串之后放置的参数mySLComposerSheet.serviceType 不被格式字符串(无占位符)使用,并且在这里没有用。因此错误提示“格式字符串未使用数据参数(即mySLComposerSheet.serviceType)”。


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

    • 如果您真的想在字符串中的某处插入serviceType,只需在格式字符串中的位置添加一个%@(因为serviceType 是一个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]];
      
    • 但我想实际上你不想在你的 initialText 字符串的任何地方插入serviceType 值(我想知道你为什么首先添加这个参数)。在这种情况下,您可以简单地删除调用stringWithFormat: 的这个无用的附加参数。或者更好,因为此时您的 stringWithFormat 调用将没有任何格式占位符,例如 %@,这无论如何使用 stringWithFormat 完全没用 ,所以直接使用字符串字面量

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

    【讨论】:

    • 感谢您的建议,我现在已经取出了 serviceType,因为它不需要并且效果很好!再次感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-21
    • 1970-01-01
    • 2018-09-21
    • 2013-01-01
    • 2017-09-28
    • 2019-07-23
    • 1970-01-01
    相关资源
    最近更新 更多