2011-12-27 2 views
0

내 애플 리케이션 메신저에서 특정 picker 특정 값을 얻을 수있는 작업 시트에서 4 pickerviews 사용하여? 이있는 나는 그것을 얻을. 방법을 사용했다,하지만 난 그것을 얻을 수있는 더 좋은 방법이 필요합니다., PLZ 도와주세요.,다른 액션 시트에서 많은 피커 뷰를 사용합니까?

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

감사합니다 Cyprian., i hav 지금 편집했습니다 – Bala

답변

0

는 각 선택기에 대한 태그를 설정할 수 있습니다. TAG 값을 사용하여 특정 선택기에서 특정 값을 가져옵니다. 지금까지 각 선택기의 선택에 대한 응답으로, 내가 EAActionSheetPicker를 사용하는 것이 좋습니다 것입니다, 지금

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

: 당신이했던 것처럼

+0

초보자, 내가 그것에 대한 몇 가지 링크를 제공 할 수 있습니다. 내가 태그를 설정하는 방법을 모르겠다., – Bala

+0

간단하지만 위대한., 고마워 친구., – Bala

+0

환영 :) 행복 :) 코딩 :) – Manjunath

0

, 당신은 설정에 다음 위임 방법이 필요합니다. 그것은 만드는 다음과 같은 선택적 위임 메소드를 가지고 당신은 단지 관련 응답에 textField 각 pickerView을 접선에 의해 권리를 설정해야합니다

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

쉽게 생활. repo에서 예제 프로젝트를 확인하여 내가 무슨 말을하고 있는지 확인하십시오.

관련 문제