繁体   English   中英

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

[英]Expression Result Unused in 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];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM