Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocoa 将变量插入NSMutableArray对象_Cocoa_Nsmutablearray_Iphone - Fatal编程技术网

Cocoa 将变量插入NSMutableArray对象

Cocoa 将变量插入NSMutableArray对象,cocoa,nsmutablearray,iphone,Cocoa,Nsmutablearray,Iphone,我想向NSMutableArray的对象添加预定义字符串。我以为您会使用%@,但显然下面的代码执行得不好。先谢谢你 arrayData = [[NSMutableArray alloc] initWithObjects:@"%@ you look tired." name, @"Why do you smell so bad?", @"I ha

我想向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]; 

%@
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]; 

%@
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]; 

每当你做一个格式化字符串时,在它和你要替换的变量之间加一个逗号。上面,你应该有@“你看起来很累”,name…每当你做一个格式化字符串时,在它和你要替换的变量之间加一个逗号。上面,你应该有@“你看起来很累”,名字。。。