将变量插入NSMutableArray对象

Mic*_*ici 0 iphone cocoa nsmutablearray

我想在NSMutableArray的对象中添加一个预定义的字符串.我以为你会用%@,但显然下面的代码执行得不好.先感谢您

arrayData = [[NSMutableArray alloc]
               initWithObjects:@"%@ you look tired." name,
                               @"Why do you smell so bad?",
                               @"I have to go potty!",
                               @"%@ put your pants on!" name,
                               @"Mommy!",
                               @"Daddy!",
                               @"NOOOOOO!",
                               @"When are we going to get there?",
                               @"I HATE YOU!",
                               nil]; 
Run Code Online (Sandbox Code Playgroud)

pgb*_*pgb 5

%@stringWithFormat:通话中有效.您的代码应如下所示:

arrayData = [[NSMutableArray alloc] initWithObjects:
                  [NSString stringWithFormat:@"%@ you look tired.", name],
                  @"Why do you smell so bad?",
                  @"I have to go potty!",
                  [NSString stringWithFormat:@"%@ put your pants on!", name],
                  @"Mommy!",
                  @"Daddy!",
                  @"NOOOOOO!",
                  @"When are we going to get there?",
                  @"I HATE YOU!",
                  nil]; 
Run Code Online (Sandbox Code Playgroud)