2013-03-03 178 views
-1

我收到错误消息:expected ':'可能是因为下面的短语initWithTitle:@"You downloaded %i boards", iboard。你能帮我解决吗?格式说明符错误

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"You downloaded %i boards", iboard message:@"Press Ok to continue" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 
      [alert show]; 
+0

什么方法做,不这样做,为什么你在做的假设?谁告诉过你可以使用可变参数格式和任何期望使用'NSString'的方法? – 2013-03-03 16:04:58

回答

2

更换

initWithTitle:@"You downloaded %i boards", iboard 

initWithTitle:[NSString stringWithFormat:@"You downloaded %i boards", iboard] 
2

你已经做了惹你的代码。

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"You downloaded %i boards", iboard message:@"Press Ok to continue" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 

它应该是:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"You downloaded %i boards", iboard] 
               message:@"Press Ok to continue" 
               delegate:self 
             cancelButtonTitle:@"Ok" 
             otherButtonTitles:nil]; 
+0

不,不应该。检查其他答案。 – 2013-03-03 16:06:07

+0

@ H2CO3:我正在输入答案,现在完成了。如果仍然有任何错误暗示。 – 2013-03-03 16:07:00

+1

现在很好。 – 2013-03-03 16:07:37