Having UIPickerView displayed when button is tapped
Hello guys,
There's some issue with my UIPickerView controller. The data won't pop up in it. The 'Drum' by itself is visible but empty.
My code is:
- (void)viewDidLoad
{
[[self navigationController]setToolbarHidden:YES animated:YES];
[self setItemShow:theItem];
self.uiPickerViewData=[[[NSMutableArray alloc]initWithObjects:@"One",@"Two", nil]autorelease];
[super viewDidLoad];
}
And method which will work when button is getting tapped on
- (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.dataSource=nil;
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];
}
-(void)setQualityIntoDB
{
// int index;
DBAccess *access=[[DBAccess alloc]init];
[access closeDataBase];
[access release];
}
-(void)cancel
{
[actionSheet dismissWithClickedButtonIndex:0 animated:YES];
[actionSheet release];
}
The help is much appreciated. Thank you in advance
Related Article: Display another view when triggered
is a Objective-C discussion thread by JakeA that has 2 replies, was last updated 1 year ago and has been tagged with the keywords: cocoa, objective-c, view.
Nfurman
Junior Poster in Training
69 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0