我正在学习Objective-C,我想用一个词替换警报中的%@。这是我的代码:UIAlert With%@
NSString *myString = @"John";
UIAlertView *myAlert = [[UIAlertView alloc]initWithTitle:@"Welcome:%@", myString message:...
有人可以修复代码吗?谢谢!
我正在学习Objective-C,我想用一个词替换警报中的%@。这是我的代码:UIAlert With%@
NSString *myString = @"John";
UIAlertView *myAlert = [[UIAlertView alloc]initWithTitle:@"Welcome:%@", myString message:...
有人可以修复代码吗?谢谢!
UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:[@"Welcome " stringByAppendingString:myString] ...];
一般来说,当你有%@
您的字符串就意味着某种形式的字符串无论如何都会更换
您需使用stringWithFormat:
方法NSString *
退房的Apple Documentation for NSString *
对你来说,你只需要做到以下几点
NSString *myString = @"John";
UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"Welcome: %@", myString]
message:@"Some Message"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK", nil];
你会好吧将中的stringWithFormat:
替换为您的字符串(myString
)