[英]Expression Result Unused in iOS UIAlertView
I'm still a newb with iOS and I'm a little stuck creating an alert view combining regular text and variables. 我仍然是iOS的新手,我有点难以创建结合常规文本和变量的警报视图。 I'm getting an "expression result unused" warning on the initWithTitle line and I don't know how to fix it.
我在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];
Right now, with the warning, everything compiles but my alert title is just "foo" instead of "hello foo". 现在,有了警告,一切都会编译,但是我的警报标题只是“ foo”,而不是“ hello foo”。
If I remove the parentheses I get a syntax error on the next line. 如果删除括号,则在下一行会出现语法错误。
Create the title as follows: 如下创建标题:
UIAlertView *myAlert = [[UIAlertView alloc]
initWithTitle: [NSString stringWithFormat:@"Hello %@",name]
message: @"You're looking mighty fine today"
delegate: nil
cancelButtonTitle: @"I'm awesome"
otherButtonTitles: nil];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.