2011-03-19 5 views
1

버튼을 클릭하면 UIPickerView를 만드는 방법을 명확하게 설명 할 수 있습니까? 제발 도와주세요 ... 고마워요! 이버튼을 클릭 한 후 UIPickerView를 만드는 방법은 무엇입니까?

-(IBAction)buttonPressed1:(id)sender{ 

    CGSize pickerSize = [myLocationPickerView sizeThatFits:CGSizeZero]; 
    myLocationPickerView.frame = CGRectMake(0.0,250,pickerSize.width,pickerSize.height); 

    [self.view addSubview:myLocationPickerView];} 

- (void)viewDidLoad { 

    [super viewDidLoad]; 

    arrayNo = [[NSMutableArray alloc] init]; 
    [arrayNo addObject:@" example 1 "]; 
    [arrayNo addObject:@" example 2 "]; 
    [arrayNo addObject:@" example 3 "]; 
    [arrayNo addObject:@" example 4 "]; 
    [myLocationPickerView selectRow:0 inComponent:0 animated:NO]; 

} 



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


- (void)myLocationPickerView:(UIPickerView *)myLocationPickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component; 
{ 
    mlabel.text= [arrayNo objectAtIndex:row]; 
} 



- (NSInteger)myLocationPickerView:(UIPickerView *)myLocationPickerView numberOfRowsInComponent:(NSInteger)component; 
{ 
    return [arrayNo count]; 
} 



- (NSString *)myLocationPickerView:(UIPickerView *)myLocationPickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component; 
{ 
    return [arrayNo objectAtIndex:row]; 

} 

답변

-1

- 아래에서와 같이 실제로

내가 무슨 짓을했는지 내가 피커 뷰를 보여되지만 데이터가없는 버튼을 클릭하면, 아래의 코드를 찾을하시기 바랍니다 코드입니다 상황에 따라 몇 가지 방법이 있습니다. 가장 직접적인 방법은 인터페이스 빌더에 xib를 작성하고 버튼을 클릭 할 때 새보기를 누르는 것입니다.

다른 방법은 프로그래밍 방식으로보기를 어셈블 한 다음 선택기 뷰를 추가하는 것입니다. 당신은 정말로 어떤 버튼이 클릭되고 있는지, 어디서 어려움을 겪고 있는지, 그리고 얼마나 많은 버튼을 이미 할 수 있는지 명확히해야합니다.

편집 : 가장 많이 사용하는 방법을 잊어 버렸습니다. 모던하게 xib 제시 :

// push modal controller 
EditViewController *editController = [[EditViewController alloc] initWithNibName:@"EditView" 
                      bundle:nil]; 
editController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
editController.delegate = self; 

editController.selectedSyllableNumber = tempSyllable.nameNumber; 
editController.selectedDirectionNumber = tempSyllable.directionNumber; 
editController.sequenceType = tempSyllable.exercise.typeNumber; 

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:editController]; 
[self presentModalViewController:navController 
         animated:YES]; 
관련 문제