views:

466

answers:

2

I have a method with the following code:

NSMutableArray *pickerArray = [[NSMutableArray alloc] init];

    int i;

    for(i = 1; i <= 7; i++) {
     NSString *myString = [NSString stringWithFormat:@"%@", i];
     [pickerArray addObject:myString];
    }

    for(i = 1; i <= 7; i++) {
     NSString *fieldName = [[NSString alloc] initWithFormat:@"column%d", i];

     [self setValue:pickerArray forKey:fieldName]; // setValue or initWithArray ???

     [fieldName release];
     [pickerArray release];
    }

    srandom(time(NULL));

When I build the application everything builds correctly but it crashes on start in the console i get the following error:

* -[NSCFString superview]: unrecognized selector sent to instance 0x380da90 * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString superview]: unrecognized selector sent to instance 0x380da90'

If instead of using an array containing strings I use UIImageView containing UIImages then everything works correctly...

I only would like to populate my picker with an array of numbers from 1 to 50...

Any help would be really appreciated... this thing is driving me mad :)

A: 

I don't think you want [myString release]; in your first for loop as the string you create is auto-released (rule of thumb, anything that is created without alloc, init, or new is auto-released)

ACBurk
You are totally right, that was my last attempt of making it work... no luck even if I'm not releasing the string... any other idea? Thanks anyway for your answer!
noboruwatanabe
can you throw in some nslog() so we know where it is crashing? also, isn't putting [pickerArray release]; inside of the second for loop over-releasing the pickerArray?
ACBurk
A: 

Problem solved.... was something to do with the number of element in the pickerview, nothing to do with the method itself! Thanks anyway!

noboruwatanabe
If you have solved your own problem, consider editing this answer to include that information and accepting it as the answer.
kersny