表达式结果在iOS UIAlertView中未使用



我还是iOS的新手,创建一个结合常规文本和变量的警报视图有点困难。我在initWithTitle行上收到一个"表达式结果未使用"警告,我不知道如何修复它

name = @"foo";
//now create the alert
UIAlertView *myAlert = [[UIAlertView alloc]
                        initWithTitle: (@"Hello %@", name)
                        message: @"You're looking mighty fine today"
                        delegate: nil
                        cancelButtonTitle: @"I'm awesome"
                        otherButtonTitles: nil];
//show the alert
[myAlert show];

现在,有了警告,一切都在编译,但我的警报标题只是"foo",而不是"hello-foo"。

如果我去掉括号,下一行就会出现语法错误。

创建标题如下:

UIAlertView *myAlert = [[UIAlertView alloc]
                    initWithTitle: [NSString stringWithFormat:@"Hello %@",name]
                    message: @"You're looking mighty fine today"
                    delegate: nil
                    cancelButtonTitle: @"I'm awesome"
                    otherButtonTitles: nil];

最新更新