2012-01-13 6 views
0

헤더는 지금 내가 관리하려고하는 것을 완전히 설명합니다. 간단히 말해, 나는 here에서 예를 좋아했습니다. 단 하나의 문제가 있습니다.이 예에서는 일반적인 UIPickerView 대신 UIDatePicker가 사용됩니다. 내 문제는 NSMutableArray에서 데이터로 내 UIPickerView를 입력 할 수 없다는 것입니다. 나는 '드럼'을 움직이게하는 세 가지 필수적인 방법을 사용하여 일반적인 방법으로 그것을 달성하려고 노력했다.버튼을 누를 때 UIPickerView가 표시됩니다.

이제 viewDidLoad : self.uiPickerViewData = [[NSMutableArray alloc] initWithObjects : @ "One", @ "Two", nil];

//when tapping on Set Quality button 
- (IBAction)setQuality:(id)sender 
{ 

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

CGRect pickerFrame=CGRectMake(0, 44, 0, 0); 
qualityPicker=[[UIPickerView alloc]initWithFrame:pickerFrame]; 
qualityPicker.delegate=self; 
[actionSheet addSubview:qualityPicker]; 

[qualityPicker release]; 

UIToolbar *toolBar=[[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, actionSheet.bounds.size.width, 44)]; 
[toolBar setBarStyle:UIBarStyleDefault]; 
[toolBar sizeToFit]; 

UIBarButtonItem *spacer=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; 
UIBarButtonItem *setButton=[[UIBarButtonItem alloc]initWithTitle:@"Set" style:UIBarButtonSystemItemCancel target:self action:@selector(setQualityIntoDB)]; 
UIBarButtonItem *cancelButton=[[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonSystemItemCancel target:self action:@selector(cancel)]; 

[toolBar setItems:[NSArray arrayWithObjects:spacer,setButton,cancelButton, nil]animated:NO]; 
[spacer release]; 
[setButton release]; 
[cancelButton release]; 

[actionSheet addSubview:toolBar]; 
[toolBar release]; 

[actionSheet showInView:self.view]; 
[actionSheet setBounds:CGRectMake(0, 0, 320, 485)]; 
} 

그리고 내가 예상 한 결과를 가져 오지 않은 필수품.

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

- (NSInteger)numberOfRowsInComponent:(NSInteger)component 
{ 
    return [uiPickerViewData count]; 
} 

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

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component 
{ 
// Will be properly implemented later 

DBAccess *access=[[DBAccess alloc]init]; 
[access closeDataBase]; 
[access release]; 
} 

UIPickerView가 비어 있습니다. 문제가 어디 있니?

답변

0
-(void)viewDidLoad 
{  PickerList = [[NSMutableArray alloc] init]; 
      SecondPickerList = [[NSMutableArray alloc]initWithObjects:@"0.0 cm",@"0.1 cm",@"0.2 cm",@"0.3 cm",@"0.4 cm",@"0.5 cm",@"0.6 cm",@"0.7 cm",@"0.8 cm",@"0.9 cm", nil];   

      for(int i=0;i<210;i++) 
      { 

       [PickerList addObject:[NSString stringWithFormat:@"%i cm",i]]; 
      } 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 
} 

가 난 ... 당신이 didload 또는 응용 프로그램 위임에 Mutablearray을 ALLOC 있어야 의미

+0

을 showPicker를 추가하고 ViewCo 때까지 메모리에 전체 방법이 배열을 오래 유지 컨트롤러가 출시 될 예정입니까? – NCFUSN

+0

예. 배열의 크기에 따라 달라집니다. PickerController가있는보기 컨트롤러에 입력 할 때 할당 할 수 있습니다. 다시 가져올 때 놓을 수 있습니다. 죄송합니다 내 영어 .. –

+0

그리고 그것이 작동하지 않는 경우 모든 구성 요소를 업데이 트하려고 ... [선택기 reloadAllComponents]; –

1

사용 뷰 아래에 (좌표 =을 시야 밖으로 피커 및 도구 모음을 만든 후 여기에이 방법 (0640)) :

- (void)showPicker{ 

[UIView beginAnimations:@"picker" context:nil]; 
[UIView setAnimationDuration:0.5]; 

    picker.transform = CGAffineTransformMakeTranslation(0,- pickerHeight); 
    pickerToolbar.transform = CGAffineTransformMakeTranslation(0, - pickerHeight - toolbarHeight); 

[UIView commitAnimations]; } 

-(void)hidePicker{ 
[UIView beginAnimations:@"picker" context:nil]; 
[UIView setAnimationDuration:0.5]; 

picker.transform = CGAffineTransformIdentity; 
pickerToolbar.transform = CGAffineTransformIdentity; 

[UIView commitAnimations]; } 

다음 .. 다른 당신이 원하는 무언가 작업으로 당신의 버튼을 hidePicker위한 작업으로

+0

내 UIPickerView가 채워 지거나 잘 열리거나 닫히는 동작 만 애니메이션으로 나타 납니까? – NCFUSN

+0

그들은 닫힌 작업을하고 있습니다. 죄송합니다. 질문이 제목이라고 생각했습니다. unpopulated picker의 유일한 이유는 uiPickerViewData가 비어 있거나 할당이 취소 되었기 때문입니다. 클래스 인터페이스에서 NSArray를 만들고, - (void) viewDidLoad 메서드에 할당하고 - (void)에서 해제 할 수 있습니다. viewDidUnload – Lolloz89

관련 문제