2012-11-24 20 views

回答

0

看到下面的代碼希望它會幫助你...享受代碼

-(void)showPicker{ 

    UIToolbar *toolPicker = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; 
    toolPicker.barStyle = UIBarStyleDefault; 

    UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleBordered target:self action:@selector(hidePicker)]; 

    [toolPicker setItems:[NSArray arrayWithObjects:cancelButton, nil]]; 

    pickerCategory = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0, 44.0, 0.0, 0.0)]; 
    pickerCategory.delegate=self; 
    pickerCategory.dataSource=self; 
    pickerCategory.showsSelectionIndicator = YES; 
    txtCategory.inputView=pickerCategory; 
    [pickerCategory addSubview:toolPicker]; 

    CGRect thePickerFrame = pickerCategory.frame; 
    thePickerFrame.origin.y = toolPicker.frame.size.height; 
    [pickerCategory setFrame:thePickerFrame]; 

    UIView *view = [[UIView alloc] init]; 
    [view addSubview:pickerCategory]; 
    [view addSubview:toolPicker]; 

    UIViewController *vc = [[UIViewController alloc] init]; 
    [vc setView:view]; 
    [vc setContentSizeForViewInPopover:CGSizeMake(320, 260)]; 

    popover = [[UIPopoverController alloc] initWithContentViewController:vc]; 


    [popover presentPopoverFromRect:txtCategory.bounds inView:txtCategory permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 


} 
-(IBAction)hidePicker{ 
    [popover dismissPopoverAnimated:YES]; 
}