Can help to clarify on how to create the UIPickerView once the button is clicked? Please give a help…Thanks a lot!
Actually as shown in below is the code that what i did, once i clicked the button the picker view is showed but doesn’t have any data,please find the below code:-
-(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];
}
There are a couple ways to do it, depending on your situation. The most straightforward way is to create a xib in interface builder and push that new view when the button is clicked.
another way would be to programmatically assemble the view and then add the pickerview. you really need to clarify what button is being clicked, where you are having difficulty and how much you can already do.
EDIT: I forgot the method I use most. Present the xib modally: