Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<ol> <li>Create 3 UiPickerView using Code after the Database read is done</li> <li>Set The values according to the database</li> <li>Set separate Tags (1,2,3) for each UIPicker.Then you can get it again every where. </li> <li>Set the UiPickerView delegates.</li> </ol> <p>You can check out the sample <a href="http://www.iphonesdkarticles.com/2009/01/uipickerview-creating-simple-picker.html" rel="nofollow">here</a></p> <p>Use <strong>[yourPicker selectRow:10 inComponent:0 animated:YES];</strong> to set picker selected value</p> <p><strong>Sample Code to Add UIPicker</strong> </p> <pre><code>-(void)displayPicker{ @try { UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 200, 44)]; pickerToolbar.barStyle = UIBarStyleBlackOpaque; [pickerToolbar sizeToFit]; NSMutableArray *barItems = [[NSMutableArray alloc] init]; UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(pickerCancel:)]; cancelBtn.tag = 1; [barItems addObject:cancelBtn]; [cancelBtn release]; cancelBtn = nil; /* Uncomment this line to add label to Timer/Counter. NSString *popUpTitleText = [self getPopUpTitleText:@"My Text"]; UIBarButtonItem *titleBtn = [[UIBarButtonItem alloc] initWithTitle:popUpTitleText style:UIBarButtonItemStylePlain target:nil action:nil]; [barItems addObject:titleBtn]; [titleBtn release]; titleBtn = nil; */ UIBarButtonItem *flexItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; flexItem.width = 64; [barItems addObject:flexItem]; [flexItem release]; flexItem = nil; UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(pickerDone:)]; doneBtn.tag = 1; [barItems addObject:doneBtn]; [doneBtn release]; doneBtn = nil; [pickerToolbar setItems:barItems animated:YES]; [barItems release]; barItems = nil; CGRect pickerFrame = CGRectMake(0, 40, 0, 216); UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame]; pickerView.showsSelectionIndicator = YES; pickerView.tag = 1; pickerView.dataSource = self; pickerView.delegate = self; CGRect pickerRect = pickerView.bounds; pickerView.bounds = pickerRect; UIViewController* popoverContent = [[UIViewController alloc] init]; UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 344)]; popoverView.backgroundColor = [UIColor whiteColor]; pickerView.frame = CGRectMake(0, 44, 200, 216); [pickerView selectRow:1 inComponent:0 animated:YES]; //set your selected (Database) value here. [popoverView addSubview:pickerToolbar]; [popoverView addSubview:pickerView]; popoverContent.view = popoverView; //resize the popover view shown //in the current view to the view's size popoverContent.contentSizeForViewInPopover = CGSizeMake(200, 244); //create a popover controller popoverController.delegate = nil; if (popoverController.popoverVisible == YES) { [popoverController dismissPopoverAnimated:YES]; } [popoverController release]; popoverController = nil; popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent]; CGRect popoverRect = [self.view convertRect:yourFrame(CGrect) fromView:[yourView superview]]; popoverRect.origin.y = popoverRect.origin.y + 15; popoverController.delegate = self; popoverRect.size.width = MIN(popoverRect.size.width, 100) ; popoverRect.origin.x = float yourXvalue; [popoverController presentPopoverFromRect:popoverRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES]; //release the popover content [popoverView release]; [popoverContent release]; [pickerToolbar release]; [pickerView release]; popoverView = nil; popoverContent = nil; pickerToolbar = nil; pickerView = nil; } @catch (NSException * ex) { NSLog(@"Exception in YourClass Method: displayPicker() Name:%@ Reason:%@",[ex name],[ex reason]); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload