Objective c 在现有文本中使用字符串-ObjC

Objective c 在现有文本中使用字符串-ObjC,objective-c,string,popup,Objective C,String,Popup,好的,我要做的是弹出一个小框,上面写着“你好,约翰!” “John”将是字符串的值 我更像是一个C#程序员,所以类似这样 Console.WriteLine("Welcome, " + name + "!"; 这是我现在的密码 - (void)viewDidLoad { [super viewDidLoad]; NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; NSString *name = [prefs strin

好的,我要做的是弹出一个小框,上面写着“你好,约翰!”

“John”将是字符串的值

我更像是一个C#程序员,所以类似这样

Console.WriteLine("Welcome, " + name + "!";
这是我现在的密码

- (void)viewDidLoad
{
[super viewDidLoad];
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *name = [prefs stringForKey:@"name"];
UIAlertView *welcome = [[UIAlertView alloc] initWithTitle:(@"Welcome back, " + "%@", name)message:@"Welcome back :)" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Yes",nil];

[welcome show];
}

简单的方法是使用[NSString stringWithFormat:(NSString*)格式,,…]

这条线应该是这样的:

UIAlertView *welcome = [[UIAlertView alloc] initWithTitle:([NSString stringWithFormat: @"Welcome back, %@", name]) message:@"Welcome back :)" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Yes",nil];

阅读
NSString
文档并查看字符串格式。在运行代码时,我得到了错误-线程1:断点1:1。这不是错误。删除断点或按ctrl+command+Y继续。读这个谢谢!对不起,我对这一切都不熟悉。