在其他视图中使用pickerview信息?

时间:2013-02-02 20:54:37

标签: view picker tabbed

我有一个标签式应用程序。我有4个选项卡,在前2个选项卡中有选择器视图。如何在第三个选项卡中使用第一个和第二个选择器视图中提供的信息?例如:1个选择器视图:(这是你最喜欢的动物)狗,猫,马。我选择了狗。现在在第二个标签(第二个选择器视图):(颜色,无论如何)绿色,蓝色,棕色。我选择棕色。

我希望第一个信息(狗)可以在第三个标签中使用。选项:绿色,蓝色和棕色(示例)是(无论我选择)相同。但在第三种观点中应该有一只棕色的狗(如前所述,“你选择了棕色的狗”)。我希望你知道我的意思... 1.选择:狗2.棕色=第三个标签棕色狗。这就像一个小数据库...或者我该怎么做?我希望你能帮助我。

谢谢: - )

1 个答案:

答案 0 :(得分:0)

See the code 

-(IBAction)simple_picker:(id)sender{

    pickerViewPopup = [[UIActionSheet alloc] init];
    const CGFloat toolbarHeight = 44.0f;
    Picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, toolbarHeight, 0, 0)];
    Picker.showsSelectionIndicator = YES;
    Picker.dataSource = self;
    Picker.delegate = self;
    //........
    UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, toolbarHeight)];
    pickerToolbar.barStyle = UIBarStyleBlackOpaque;
    [pickerToolbar sizeToFit];
    NSMutableArray *barItems = [[NSMutableArray alloc] init];

    UIBarButtonItem *cancel= [[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(Cancel_picker:)];
    [barItems addObject:cancel];
    UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
    [barItems addObject:flexSpace];
    //....
    UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonPressed2:)];
    [barItems addObject:doneBtn];
    [pickerToolbar setItems:barItems animated:YES];
    [pickerViewPopup addSubview:pickerToolbar];

    lbl2.text=[picArray objectAtIndex:0];

    [pickerViewPopup addSubview:Picker];
    [pickerViewPopup showInView:self.view.superview];
    [pickerViewPopup setBounds:CGRectMake(0,0,self.view.frame.size.width, 464)];

}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
{
    return 1;
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
            lbl2.text= [picArray objectAtIndex:row];


}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
{

    return [picArray count];

}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
{

return [picArray objectAtIndex:row];


}


-(void)btncancelPressed2:(id)sender{
    [pickerViewPopup dismissWithClickedButtonIndex:1 animated:YES];
}

-(void)Cancel_picker:(id)sender{
    [pickerViewPopup dismissWithClickedButtonIndex:1 animated:YES];
}