格式说明符错误

时间:2013-03-03 16:00:49

标签: objective-c string-formatting

我收到错误消息: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];

2 个答案:

答案 0 :(得分:2)

替换

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

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

答案 1 :(得分: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];