Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.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
Iphone 如何创建按钮数组对象?_Iphone_Objective C_Arrays - Fatal编程技术网

Iphone 如何创建按钮数组对象?

Iphone 如何创建按钮数组对象?,iphone,objective-c,arrays,Iphone,Objective C,Arrays,我想用一个数组创建10个按钮。如何创建它?我正在使用 array = [[[NSArray alloc] initWithObjects:button1, button2] retain]; 但它告诉函数调用中缺少的Sentinel。哪里,我错了 NSArray *myButtons = [[NSArray alloc] initWithObjects:button1, button2, nil]; 现在,您的数组在分配后具有retain count 1,因此您不必保留它 当您不需要阵列时

我想用一个数组创建10个按钮。如何创建它?我正在使用

array  = [[[NSArray alloc] initWithObjects:button1, button2] retain];
但它告诉函数调用中缺少的Sentinel。哪里,我错了

NSArray *myButtons = [[NSArray alloc] initWithObjects:button1, button2, nil];
现在,您的数组在分配后具有retain count 1,因此您不必保留它

当您不需要阵列时,只需释放它

[myButtons release];
现在,您的数组在分配后具有retain count 1,因此您不必保留它

当您不需要阵列时,只需释放它

[myButtons release];

-initWithObjects:
方法必须以
nil
终止:

array = [[NSArray alloc] initWithObjects:button1, button2, nil];
//                                                       ^^^^^

另外,
+alloc
方法已经返回了一个retaincount为+1的对象。没有必要保留它。

必须终止
-initWithObjects:
方法
nil

array = [[NSArray alloc] initWithObjects:button1, button2, nil];
//                                                       ^^^^^

另外,
+alloc
方法已经返回了一个retaincount为+1的对象。无需
-保留它。

您缺少阵列的终止nil

array=[[NSArray alloc]initWithObjects:button1,button2,nil]retain]

但这可能是泄漏,因为你得到了双重保留。也许更好


array=[[NSArray arrayWithObjects:button1,button2,nil]retain]

您缺少阵列的终止nil

array=[[NSArray alloc]initWithObjects:button1,button2,nil]retain]

但这可能是泄漏,因为你得到了双重保留。也许更好


array=[[NSArray arrayWithObjects:button1,button2,nil]retain]

我可以在数组中洗牌这些对象的顺序吗?@KennyTM:你能告诉我如何在数组中洗牌这些对象吗?你能给我一个解决方案吗?@Tacquir:你为什么不呢?我试过搜索,但没有找到想要的结果。你能帮我找到一个合适的解决方案吗?我能洗牌数组中这些对象的顺序吗?@KennyTM:你能告诉我如何洗牌数组中的这些对象吗?你能给我一个解决方案吗?@Tacquir:你为什么不呢?我试过搜索,但没有找到想要的结果。你能帮我找到一个合适的解决方案吗?[array objectAtIndex:i.frame]=CGRectMake(50,50,100,30);这句话我错了。这是一个for循环。@Tauquir:objectAtIndex需要整数。您应该首先将索引
i
处的对象检索到变量中,然后将其帧属性分配给
CGRectMake(…)
;[array objectAtIndex:i.frame]=CGRectMake(50,50,100,30);这句话我错了。这是一个for循环。@Tauquir:objectAtIndex需要整数。您应该首先将索引
i
处的对象检索到变量中,然后将其帧属性分配给
CGRectMake(…)