开发者

How to create a array of buttons Object?

开发者 https://www.devze.com 2023-01-10 19:58 出处:网络
I want to create 10 buttons using an array. How to create it? I am using array= [[[NSArray alloc] init开发者_如何学JAVAWithObjects:button1, button2] retain];

I want to create 10 buttons using an array. How to create it? I am using

array  = [[[NSArray alloc] init开发者_如何学JAVAWithObjects:button1, button2] retain];

But It tells Missing Sentinel in Function Call. Where, I am wrong?


NSArray *myButtons = [[NSArray alloc] initWithObjects:button1, button2, nil];

Now your array has retain count 1 after allocation, so you don't have to retain it.

When you don't need the array, just release it

[myButtons release];


The -initWithObjects: method have to be nil-terminated:

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

Also, the +alloc method already returns an object with retain count of +1. There's no need to -retain it.


You are missing the terminating nil for the array.

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

But thats possibly leaky as you get a double retain. Better might be.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消