Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

declan0872

macrumors newbie
Original poster
Apr 4, 2015
2
0
Hi all,

I have two view controllers. RegisterViewController and HeightPickerViewController. I have created a picker view in HeightPickerViewController and I want to display this in RegisterViewController but dont know how to.

HeightPickerViewController.h
Code:
#import <UIKit/UIKit.h>

@interface HeightPickerViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate>


@property (strong, nonatomic) NSMutableArray *feetOptions;
@property (strong, nonatomic) NSMutableArray *inchesOptions;
@property (strong, nonatomic) UIPickerView *heightPickerView;

@end

HeightPickerViewController.m
Code:
@implementation HeightPickerViewController

@synthesize feetOptions, inchesOptions, heightPickerView;

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    heightPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 100, 320, 200)];
    heightPickerView.delegate = self;
    heightPickerView.dataSource = self;
    [self.view addSubview:heightPickerView];
}

//RETURN THE NUMBER OF COLUMNS IN PICKER VIEW
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 4;
}

//RETURNS THE NUMBER OF ROWS IN EACH COMPONENT..
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    if(component == 0)
    {
        return [[self getUserDetailsHeightFeetOptions]count];
    }
    else
    {
        return [[self getUserDetailsHeightInchesOptions]count];
    }
    
}

//ADD DATA TO PICKER
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    if(component == 0)
    {
        return [NSString stringWithFormat:@"%@", [[self getUserDetailsHeightFeetOptions]objectAtIndex:row]];
    }
    else if(component == 1)
    {
        return [NSString stringWithFormat:@"Ft"];
    }
    else if (component == 2)
    {
        return [NSString stringWithFormat:@"%@", [[self getUserDetailsHeightInchesOptions]objectAtIndex:row]];
    }
    
    return [NSString stringWithFormat:@"In"];
    
    
}

- (NSArray*)getUserDetailsHeightFeetOptions
{
    feetOptions = [[NSMutableArray alloc]init];
    for (int i = 2; i < 8; i++) {
        [feetOptions addObject:[NSNumber numberWithInt:i]];
    }
    return feetOptions;
   
}

- (NSArray*)getUserDetailsHeightInchesOptions
{
    inchesOptions = [[NSMutableArray alloc]init];
    for (int i = 0; i < 12; i++) {
        [inchesOptions addObject:[NSNumber numberWithInt:i]];
    }
    return inchesOptions;

}

//WHAT HAPPENS WHEN A ROW IS PICKED
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
 
Last edited by a moderator:
Do you want to have two separate views/screens? Or do you simply want to display a UIPickerView in the RegisterViewController?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.