2011-12-27 5 views
0

?私はそれを得るための方法を使用しているに 。が、私はそれを得るためのより良い方法を必要としています。、plzは私を助けて。、異なるアクションシートで多くのピッカービューを使用していますか?どのように私は特定のピッカーから特定の値を取得することが可能なアクションシートで4 pickerviewsを使用して私のアプリイムで

-(NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component { 
    NSLog(@"pickerView"); 
    return [pickerArray count]; 
} 

- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { 
    return [pickerArray objectAtIndex:row]; 
} 

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

    if (validateButton == 0){ 

     NSInteger temp = (row*5); 
     minAsleepInt = temp; 
     minAsleepLable.text = [NSString stringWithFormat:@"%d",temp]; 
    } 
    else if(validateButton == 1){ 

     noOptInt = row+1; 
     noOptLable.text = [pickerArray objectAtIndex:row]; 
    } 
    else if(validateButton == 2){ 

     ageTypeLable.text = [pickerArray objectAtIndex:row]; 
    } 
    else if(validateButton == 3){ 

     if([pickerArray objectAtIndex:row] == @"Yes"){ 
      sleepLessBool = YES; 
     }else{ 
      sleepLessBool = NO; 
     } 
     sleepLessLable.text = [pickerArray objectAtIndex:row]; 
    } 

} 


- (IBAction)sleepLessAction:(id)sender { 

    validateButton = 3; 

    pickerArray = [[NSMutableArray alloc] init]; 
    [pickerArray addObject:@"Yes"]; 
    [pickerArray addObject:@"No"]; 


    actionSheet = [[UIActionSheet alloc] initWithTitle:nil 
                  delegate:self 
                cancelButtonTitle:nil 
               destructiveButtonTitle:nil 
                otherButtonTitles:nil]; 

    [actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent]; 

    CGRect pickerFrame = CGRectMake(0, 40, 0, 0); 

    pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame]; 
    pickerView.showsSelectionIndicator = YES; 
    pickerView.delegate = self; 

    [actionSheet addSubview:pickerView]; 

    UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Close"]]; 
    closeButton.momentary = YES; 
    closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f); 
    closeButton.segmentedControlStyle = UISegmentedControlStyleBar; 
    closeButton.tintColor = [UIColor blackColor]; 
    [closeButton addTarget:self action:@selector(dismissActionSheet) forControlEvents:UIControlEventValueChanged]; 
    [actionSheet addSubview:closeButton]; 

    [actionSheet showInView:[[UIApplication sharedApplication] keyWindow]]; 

    [actionSheet setBounds:CGRectMake(0, 0, 320, 485)]; 


} 

- (IBAction)ageTypeAction:(id)sender { 
    validateButton = 2; 

    pickerArray = [[NSMutableArray alloc] init]; 
    [pickerArray addObject:@"Child"]; 
    [pickerArray addObject:@"Teen"]; 
    [pickerArray addObject:@"Adult"]; 

    actionSheet = [[UIActionSheet alloc] initWithTitle:nil 
               delegate:nil 
            cancelButtonTitle:nil 
           destructiveButtonTitle:nil 
            otherButtonTitles:nil]; 

    [actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent]; 

    CGRect pickerFrame = CGRectMake(0, 40, 0, 0); 

    pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame]; 
    pickerView.showsSelectionIndicator = YES; 
    pickerView.delegate = self; 

    [actionSheet addSubview:pickerView]; 


    UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Close"]]; 
    closeButton.momentary = YES; 
    closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f); 
    closeButton.segmentedControlStyle = UISegmentedControlStyleBar; 
    closeButton.tintColor = [UIColor blackColor]; 
    [closeButton addTarget:self action:@selector(dismissActionSheet) forControlEvents:UIControlEventValueChanged]; 
    [actionSheet addSubview:closeButton]; 

    [actionSheet showInView:[[UIApplication sharedApplication] keyWindow]]; 

    [actionSheet setBounds:CGRectMake(0, 0, 320, 485)]; 
} 

- (IBAction)noOptAction:(id)sender { 

    validateButton = 1; 
    pickerArray = [[NSMutableArray alloc] init]; 

    [pickerArray addObject:@"1"]; 
    [pickerArray addObject:@"2"]; 
    [pickerArray addObject:@"3"]; 
    [pickerArray addObject:@"4"]; 
    [pickerArray addObject:@"5"]; 
    [pickerArray addObject:@"6"]; 
    [pickerArray addObject:@"7"]; 
    [pickerArray addObject:@"8"];  
    [pickerArray addObject:@"9"]; 

    actionSheet = [[UIActionSheet alloc] initWithTitle:nil 
               delegate:nil 
            cancelButtonTitle:nil 
           destructiveButtonTitle:nil 
            otherButtonTitles:nil]; 

    [actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent]; 

    CGRect pickerFrame = CGRectMake(0, 40, 0, 0); 

    pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame]; 
    pickerView.showsSelectionIndicator = YES; 
    pickerView.delegate = self; 


    [actionSheet addSubview:pickerView]; 


    UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Close"]]; 
    closeButton.momentary = YES; 
    closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f); 
    closeButton.segmentedControlStyle = UISegmentedControlStyleBar; 
    closeButton.tintColor = [UIColor blackColor]; 
    [closeButton addTarget:self action:@selector(dismissActionSheet) forControlEvents:UIControlEventValueChanged]; 
    [actionSheet addSubview:closeButton]; 

    [actionSheet showInView:[[UIApplication sharedApplication] keyWindow]]; 

    [actionSheet setBounds:CGRectMake(0, 0, 320, 485)]; 

} 

- (IBAction)minSleepAction:(id)sender { 

     validateButton = 0; 

    pickerArray = [[NSMutableArray alloc] init]; 
    [pickerArray addObject:@"0 Minutes"]; 
    [pickerArray addObject:@"5 Minutes"]; 
    [pickerArray addObject:@"10 Minutes"]; 
    [pickerArray addObject:@"15 Minutes"]; 
    [pickerArray addObject:@"20 Minutes"]; 
    [pickerArray addObject:@"25 Minutes"]; 
    [pickerArray addObject:@"30 Minutes"]; 
    [pickerArray addObject:@"35 Minutes"]; 
    [pickerArray addObject:@"40 Minutes"]; 
    [pickerArray addObject:@"45 Minutes"]; 
    [pickerArray addObject:@"50 Minutes"]; 
    [pickerArray addObject:@"55 Minutes"]; 
    [pickerArray addObject:@"60 Minutes"]; 

    actionSheet = [[UIActionSheet alloc] initWithTitle:nil 
               delegate:nil 
            cancelButtonTitle:nil 
           destructiveButtonTitle:nil 
            otherButtonTitles:nil]; 

    [actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent]; 

    CGRect pickerFrame = CGRectMake(0, 40, 0, 0); 

    pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame]; 
    pickerView.showsSelectionIndicator = YES; 
    pickerView.delegate = self; 


    [actionSheet addSubview:pickerView]; 


    UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Close"]]; 
    closeButton.momentary = YES; 
    closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f); 
    closeButton.segmentedControlStyle = UISegmentedControlStyleBar; 
    closeButton.tintColor = [UIColor blackColor]; 
    [closeButton addTarget:self action:@selector(dismissActionSheet) forControlEvents:UIControlEventValueChanged]; 
    [actionSheet addSubview:closeButton]; 

    [actionSheet showInView:[[UIApplication sharedApplication] keyWindow]]; 

    [actionSheet setBounds:CGRectMake(0, 0, 320, 485)]; 
} 


-(void)dismissActionSheet{ 
    [actionSheet dismissWithClickedButtonIndex:0 animated:YES]; 

} 

@end 
+0

ヒント:あなただけに問題があるコードの中で最も重要な行を貼り付けます。長い間それを理解するために、誰もあなたのクラス全体に行きません。 – Cyprian

+0

感謝シプリアン。、私は、私はタグを設定する方法を知らない。uはplzはそれのために私にいくつかのリンクを与えることができ、今 – Bala

答えて

0

は、各ピッカーのタグを設定することができます。また、TAG値を使用して特定のピッカーから特定の値を取得します。

+0

イム初心者を編集したHAV、 – Bala

+0

シンプルだが素晴らしい。、感謝の友人。、 – Bala

+0

歓迎:)幸せコーディング:) – Manjunath

0

あなたがやったとして、あなたはセットアップに次のデリゲートメソッド必要があります。今

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView { 
    return PICKER_COMPONENTS; 
} 
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component { 
    return [self.pickerOptions count]; 
} 
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { 
    return [self.pickerOptions objectAtIndex:row]; 
} 

を、限り各ピッカーの選択への応答として、私はEAActionSheetPickerを使用することをお勧めします。それはあなたが関連する応答テキストフィールドに各pickerViewをフックして、右それを設定するだけで必要があります

-(void)EAActionSheetPicker:(EAActionSheetPicker *)actionSheet 
    didDismissWithSelection:(id)selection 
       inTextField:(UITextField *)textField{ 
    // respond to your selection here 
} 

人生が容易になり、次のオプションのデリゲートメソッドを持っています。レポのサンプルプロジェクトをチェックして、私が何を話しているのか見てみましょう。

関連する問題