簡體   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