BFT*_*ick 1 string uialertview ios
我仍然是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];
Run Code Online (Sandbox Code Playgroud)
现在,有了警告,一切都会编译,但我的警报标题只是"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];
Run Code Online (Sandbox Code Playgroud)