Nat*_*ary 5 iphone xcode ios6 xcode4.5
我有点困惑为什么我得到的格式字符串没有使用ERROR'数据参数'
有没有其他人在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;
}
}];
}
Run Code Online (Sandbox Code Playgroud)
Ali*_*are 11
您所遇到的错误非常自我解释:当您使用时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]];
Run Code Online (Sandbox Code Playgroud)但我想你实际上并不想serviceType
在initialText字符串中的任何位置插入值(我想知道为什么你在第一个地方添加了这个参数).在这种情况下,你可以简单地删除你的这个无用的额外参数stringWithFormat:
.或者更好的,因为在这一点上你的stringWithFormat
电话将不会有任何格式的占位符像%@
所有,这是完全无用的使用stringWithFormat
无论如何,所以干脆直接使用字符串字面!
[mySLComposerSheet setInitialText:@"I'm listening to Boilerroom Recordings via the Boilerroom iPhone Application"];
Run Code Online (Sandbox Code Playgroud) 归档时间: |
|
查看次数: |
4752 次 |
最近记录: |