2011-11-02 15 views
13

que estoy tratando de mostrar una UIActionSheet en el IPAD con un UIPickerView en ella, tengo el código equivalente de trabajo para el iPhone por lo que mi UIPickerView delegado y cosas por el origen de datos de trabajo, pero en el iPad cuando uso -[UIActionSheet showFromRect:inView:animated:] el resultado UIPopover/UIActionSheet es demasiado pequeño y parece que no puedo establecer el tamaño del marco, tampoco se muestran ninguno de los botones.UIActionSheet en el marco del iPad demasiado pequeño

No sé si esto se debe a que están fuera de los límites o si sucede algo más. Así es como se ve mi código después de haber eliminado todos los códigos no esenciales (iPhone, etc.). ¿Alguien sabe lo que estoy haciendo mal? ¿Alguien sabe de algún ejemplo?

CGRect thePickerFrame = CGRectMake(0, 0, 320.0, 485.0); 
UIPickerView * thePickerView = [[UIPickerView alloc] initWithFrame:thePickerFrame]; 

[pickerActionSheet release], pickerActionSheet = 
     [[UIActionSheet alloc] initWithTitle:@"Choose" delegate:self 
           cancelButtonTitle:@"Cancel" 
           destructiveButtonTitle:nil 
           otherButtonTitles:@"Next", nil]; 
thePickerView.showsSelectionIndicator = YES; 
thePickerView.dataSource = self; 
thePickerView.delegate = self; 

[pickerActionSheet addSubview:thePickerView]; 
[thePickerView selectRow:0 inComponent:0 animated:NO]; 
[thePickerView release]; 

[pickerActionSheet showFromRect:currentTextField.bounds 
          inView:currentTextField animated:NO]; 
pickerActionSheet.frame = thePickerFrame; 
+0

Acabo de experimentar un poco para ver cuándo - [UIActionSheet setFrame:] se está llamando. Parece que después del bucle de evento, donde lo anterior se llama otro bucle de evento iniciado por el resultado de iOS, se llama a [UIActionSheet setFrame:] con el pequeño cuadro que se muestra. –

+1

¿No estás mejor con popover en iPad con esta funcionalidad? AFAIK ActionSheet es solo para botones. – Eimantas

Respuesta

18

Creo que UIActionSheet no es de tamaño variable, intenta hacer comentarios en el código de la línea con [pickerActionSheet addSubview:thePickerView]; y verá que el ActionSheet encaja perfecly a los botones.

Recomendaría un UIPopoverController con un UIViewController personalizado. Algo como esto:

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

UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:@"back" style:UIBarButtonItemStyleBordered target:self action:@selector(BACK_ACTION:)]; 
UIBarButtonItem *chooseButton = [[UIBarButtonItem alloc] initWithTitle:@"Choose" style:UIBarButtonItemStylePlain target:nil action:nil]; 
UIBarButtonItem *nextButton = [[UIBarButtonItem alloc] initWithTitle:@"Next" style:UIBarButtonItemStyleBordered target:self action:@selector(NEXT_ACTION:)]; 
UIBarButtonItem *fixed1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; 
UIBarButtonItem *fixed2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; 

[toolbar setItems:[NSArray arrayWithObjects:cancelButton, fixed1, chooseButton, fixed2, nextButton, nil]]; 

UIPickerView *thePickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 44, 320, 216)]; 
CGRect thePickerFrame = thePickerView.frame; 
thePickerFrame.origin.y = toolbar.frame.size.height; 
[thePickerView setFrame:thePickerFrame]; 


UIView *view = [[UIView alloc] init]; 
[view addSubview:thePickerView]; 
[view addSubview:toolbar]; 

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

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

thePickerView.showsSelectionIndicator = YES; 
thePickerView.dataSource = self; 
thePickerView.delegate = self; 

[thePickerView selectRow:0 inComponent:0 animated:NO]; 

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

Dónde popover es una variable de clase declarada en .h (UIPopoverController *popover;).

Por cierto, estoy usando ARC, por lo que no hay ninguna versión en el código.

8

Me las arreglé para que funcione de una manera tonta.

Para su referencia:
Configuración PickerView.

UIActionSheet ancho no se puede ajustar de alguna manera, por lo que tiene que ajustar pickerView en consecuencia. En altura, puede ajustar con la cantidad de "\ n" en el título de actionSheet.

UIDatePicker * pickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 0, 270, 220)]; 
pickerView.datePickerMode = UIDatePickerModeDate; 

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

[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent]; 
[actionSheet addSubview:pickerView]; 
[actionSheet showFromRect:button.frame inView:button.superview animated:YES]; 
[actionSheet release]; 

Establecer marco o encuadernado no funciona para mí.

[actionSheet setBounds:pickerView.frame]; 
[actionSheet setFrame:pickerView.frame]; 



acordaron la utilización de UIPopoverController, pero no sé por qué, se puso un retraso IU grave cuando pongo UIDatePickerView en popover (Tomó casi 1 seg retraso para que aparezca) que no puedo encuentra la causa raíz Entonces tenemos que recurrir al método anterior.


Happy Coding.

+0

Aunque hacky, esto es al menos fácil de implementar en una aplicación universal. ¡Gracias! –

Cuestiones relacionadas