我正在學習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
)