ERROR data argument not used by format string on mySLComposerSheet

大城市里の小女人 提交于 2020-01-02 04:27:07

问题


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

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;
    }
}];

}

回答1:


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).

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:

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


来源:https://stackoverflow.com/questions/12621430/error-data-argument-not-used-by-format-string-on-myslcomposersheet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!