簡體   English   中英

將數據從UIPickerView傳遞回其委托

[英]Passing data from a UIPickerView back to its delegate

我在自定義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];


        }
    }


}

我有兩個組成部分,但是為了使其“通用”(與特定情況無關),我不想在這里和那里硬寫數字。

在所示的示例中,我不明白為什么NSLog對變量foo顯示正確,而對NSMutableArray pepe顯示null。

有任何想法嗎? 提前致謝。

您沒有分配可變數組pepe。

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

實際上,您可以在init方法上執行此操作,並將pepe聲明為屬性

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM