Note that there are some explanatory texts on larger screens.

plurals
  1. POUIPickerView doesn't appear
    primarykey
    data
    text
    <p>In a ViewController call by <strong>push</strong>, I try to programmatically display a ComboBox. This combobox implement UIPickerView delegate protocol and add a .xib file.</p> <p>When i run the app, i can see my combobox on the screen, but when i click on it, nothing append. Normally the pickerview will be displayed.</p> <p>What i don't understand, is in another viewcontroller call <strong>modal</strong> it works fine</p> <pre><code>// // ComboBox.h // #import &lt;UIKit/UIKit.h&gt; @interface ComboBox : UIViewController&lt;UIPickerViewDelegate, UIPickerViewDataSource, UITextFieldDelegate&gt; { UIPickerView* pickerView; IBOutlet UITextField* textField; NSMutableArray *dataArray; } -(void) setComboData:(NSMutableArray*) data; //set the picker view items -(void) setPlaceholder:(NSString*) label; @property (retain, nonatomic) NSString* selectedText; //the UITextField text @property (retain, nonatomic) IBOutlet UITextField* textField; //the UITextField @end // // ComboBox.m // #import "ComboBox.h" @implementation ComboBox @synthesize selectedText; @synthesize textField; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { return [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } #pragma mark - View lifecycle - (void)viewDidLoad { [super viewDidLoad]; } - (void)viewDidUnload { [super viewDidUnload]; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait); } //-- UIPickerViewDelegate, UIPickerViewDataSource - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView; { return 1; } - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { textField.text = [dataArray objectAtIndex:row]; selectedText = textField.text; } - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component; { return [dataArray count]; } - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component; { return [dataArray objectAtIndex:row]; } //-- ComboBox -(void) setComboData:(NSMutableArray*) data { dataArray = data; } -(void) setPlaceholder:(NSString *)label { textField.placeholder = label; } -(void)doneClicked:(id) sender { [textField resignFirstResponder]; //hides the pickerView } - (IBAction)showPicker:(id)sender { pickerView = [[UIPickerView alloc] init]; pickerView.showsSelectionIndicator = YES; pickerView.dataSource = self; pickerView.delegate = self; UIToolbar* toolbar = [[UIToolbar alloc] init]; toolbar.barStyle = UIBarStyleBlackTranslucent; [toolbar sizeToFit]; //to make the done button aligned to the right UIBarButtonItem *flexibleSpaceLeft = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; UIBarButtonItem* doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(doneClicked:)]; [toolbar setItems:[NSArray arrayWithObjects:flexibleSpaceLeft, doneButton, nil]]; //custom input view textField.inputView = pickerView; textField.inputAccessoryView = toolbar; } - (BOOL)textFieldShouldBeginEditing:(UITextField *)aTextField { [self showPicker:aTextField]; return YES; } @end </code></pre> <p>the viewdidload of my viewcontroller</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; NSMutableArray* ServeurArray = [[NSMutableArray alloc] init]; [ServeurArray addObject:@"1"]; [ServeurArray addObject:@"2"]; [ServeurArray addObject:@"3"]; comboServeur = [[ComboBox alloc] init]; [comboServeur setComboData:ServeurArray]; //Assign the array to ComboBox comboServeur.view.frame = CGRectMake(95, 220, 130, 31); //ComboBox location and size (x,y,width,height) [self.view addSubview:comboServeur.view]; } </code></pre> <p>thx for your answers</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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