【问题标题】:Can't figure out an error with stringWithFormat无法找出 stringWithFormat 的错误
【发布时间】:2012-04-02 13:43:57
【问题描述】:

我在使用 NSString stringWithFormat 时遇到了一个非常基本的问题。我想取用户输入的名称并在 alertView 中显示:欢迎用户名。

NSString *welcomeMessage = [NSString stringWithFormat:(@"Welcome %@", passedData)];
UIAlertView *alert = [[UIAlertView alloc]   //show alert box with option to play or exit
                      initWithTitle: welcomeMessage 
                      message:@"Once you press \"Play\" the timer will start. Good luck!" 
                      delegate:self 
                      cancelButtonTitle:@"I want out!" 
                      otherButtonTitles:@"Play",nil];
[alert show];

passedData 是已输入的用户名。我现在的方式 - 只有用户名显示在警报框的标题中,而不是“欢迎”部分。我知道我在这里缺少一些真正的基本知识,但希望能得到一些帮助。

【问题讨论】:

    标签: iphone objective-c nsstring uialertview stringwithformat


    【解决方案1】:

    我认为不需要()。尝试使用它:

    NSString *welcomeMessage = [NSString stringWithFormat:@"Welcome %@", passedData];
    

    而不是

    NSString *welcomeMessage = [NSString stringWithFormat:(@"Welcome %@", passedData)];
    

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多