2012-01-04 7 views
5

Tengo un UIPickerView y necesito que se muestre dentro de una UIActionSheet en iPad (funciona muy bien en iPhone, no en iPad).Agregar un UIPickerView dentro de UIActionSheet en iPad

Tengo un botón en la vista cuando hago clic en ejecuto el siguiente código:

- (IBAction) buttonPressed:(id)sender 
{ 
    NSLog(@"I am pressed"); 

    UIPickerView* picker = [[UIPickerView alloc] initWithFrame:CGRectMake(100,200,500,500)]; 
    picker.delegate = self; 
    picker.dataSource = self; 
    picker.showsSelectionIndicator = YES; 
    [self.view addSubview:picker];  
} 

// El delegado del origen de datos y funciones PickerView:

// returns the number of 'columns' to display. 
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView 
{ 
    return 1; 
} 

// returns the # of rows in each component.. 
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component 
{ 
    return 5; 
} 

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component 
{ 
    return @"One"; 
} 

pero cuando el cambio lo anterior código para agregar el PickerView dentro de un actionSheet, ¡Muestra solo el encabezado de la hoja de acción pero sin PickerView dentro de él!

El código modificado de la siguiente manera:

- (IBAction) buttonPressed:(id)sender 
{ 
    NSLog(@"I am pressed"); 

    UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:@"My PickerView" 
               delegate:nil 
            cancelButtonTitle:nil 
           destructiveButtonTitle:nil 
            otherButtonTitles:nil]; 

    UIPickerView* picker = [[UIPickerView alloc] initWithFrame:CGRectMake(100,200,500,500)]; 
    picker.delegate = self; 
    picker.dataSource = self; 
    picker.showsSelectionIndicator = YES; 

    [actionSheet addSubview:picker]; 
    [actionSheet showFromRect:CGRectMake(0, 0, 320, 469) inView:self.view animated:NO]; 

} 

Respuesta

4

¡Yo apesta, voy a usar un UIPopoverController con un UITableViewController dentro! .. ¡Gracias de cualquier manera!

1

tratar de modificar el marco del selector. (100, 200) en (x, y) podría no ser una buena posición.

+0

Cuando cambié el selector InitLine a 'UIPickerView * selector = [[UIPickerView alloc] initWithFrame: CGRectMake (0,0,320,469)];' Ahora puedo ver una parte muy pequeña del PickerView dentro de la Hoja de Acción pero se muestra la hoja de acción como un cuadrado muy pequeño, ¿cómo puedo hacerlo más grande, estoy tratando de cambiar su ancho y alto, pero parece que no funciona! –

+0

Intenta establecer el cancelButtonTitle en algunos NSString para ver si el tamaño cambia. –

+0

¡Asqueroso, en su lugar usaré un 'UIPopoverController' con un' UITableViewController'! .. ¡Gracias de cualquier manera! –

-4

creo que la línea debe ser ([actionSheet addSubview:picker];) [actionSheet addSubview:picker.view];
que estaba teniendo el mismo problema, pero utilizando UIWindow.

+0

'UIPickerView' hereda de' UIView'; no tiene una propiedad, 'view', propia. – Olie