We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,459 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

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

2
Contributors
1
Reply
4 Months
Discussion Span
1 Year Ago
Last Updated
3
Views
Nfurman
Junior Poster in Training
69 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

I would try getting rid of the autorelease in the above line of code and see if it helps.

scottdurica
Newbie Poster
4 posts since Jan 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.5160 seconds using 2.68MB