I have a UIPickerView inside a custom tableViewCell (subclassed). I'am able to populate it and get data back from it. More or less.

I have this method I implement in order to get info everytime some of the components changed:

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{



    if (self.pickerDelegate !=nil &&[self.pickerDelegate conformsToProtocol:@protocol(PickerCellDelegate)]) {


        if ([self.pickerDelegate respondsToSelector:@selector(somethingOnThePickerIsSelected:selectionArray:)]){


            NSMutableArray *pepe;

            for (int i=0; i<[[self.cellPickerInputDictionary objectForKey:@"components"] count]; i++) {

                NSObject*foo=[[[self.cellPickerInputDictionary objectForKey:@"components"] objectAtIndex:i] objectAtIndex:[self.cellPicker selectedRowInComponent:i]];

                [pepe addObject:foo];

                NSLog (@"foo: %@", foo);

            }

            NSLog (@"pepe: %@", pepe);

          [self.pickerDelegate somethingOnThePickerIsSelected:self selectionArray:pepe];


        }
    }


}

I have two components, but in order to make it "universal" (independent of a particular situation) I don't want to hard-write numbers here and there.

In the example shown, I don't understand why the NSLog shows correct for the variable foo but shows null for the NSMutableArray pepe.

Any ideas? Thanks in advance.

有帮助吗?

解决方案

You are not allocating your mutable array pepe.

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

In fact, you can do that on your init method, and declare pepe as property

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top