将数据从UIPickerView传递回其委托

时间:2014-04-02 22:03:00

标签: ios uitableview uipickerview delegation

我在自定义tableViewCell(子类)中有一个UIPickerView。我能够填充它并从中获取数据。或多或少。

我实现了这个方法,以便每次更改某些组件时获取信息:

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


        }
    }


}

我有两个组件,但为了使它成为普遍的&#34; (独立于特定情况)我不想在这里和那里写数字。

在显示的示例中,我不明白为什么NSLog对变量foo显示正确但对NSMutableArray pepe显示为null。

有什么想法吗?提前谢谢。

1 个答案:

答案 0 :(得分:1)

你没有分配你的可变数组pepe。

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

实际上,您可以在init方法上执行此操作,并将pepe声明为属性