views:

63

answers:

3

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

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

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

+1  A: 
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];
Michael
@Michael [array objectAtIndex:i.frame] = CGRectMake(50, 50, 100, 30);Where I am wrong in this syntax. Here is a for loop.
Tauquir
@Tauquir: objectAtIndex requires integer. You should first retrieve object at index `i` into variable then assign its frame property to `CGRectMake(...)`;
Michael
+1  A: 

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.

KennyTM
+1  A: 

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

Warren Burton
@Warren : Can I shuffle the order of these objects in the array?
Tauquir
@Tauquir: Yes .
KennyTM
@KennyTM: Can you tell me how to shuffle these in the Array? Can You Provide me the Solution?
Tauquir
@Tacquir: Why don't you [search](http://stackoverflow.com/search?q=objective-c+shuffle)?
KennyTM
@Warren: I tried a search but could not find the desire result. Can you help me out with a proper solution?
Tauquir