UIPickerView: numberOfRowsInComponent is being called twice for same component and is not displaying row titles <p>I'm trying to setup a login form for my application and it is the UIPickerView is not showing the row data. What I am seeing is that the numberOfRowsInComponent is being called twice? But titleForRow is only being called once per row.</p> <p>Debug output:</p> <pre><code>2011-06-07 11:07:31.096 myECG[19689:207] numberOfRowsInComponent: 2 : 0 2011-06-07 11:07:31.096 myECG[19689:207] numberOfRowsInComponent: 2 : 0 2011-06-07 11:07:31.098 myECG[19689:207] USA : 0 2011-06-07 11:07:31.098 myECG[19689:207] Canada : 0 </code></pre> <p><strong>LoginViewController.h</strong></p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface LoginViewController : UIViewController &lt;UIPickerViewDataSource, UIPickerViewDelegate&gt; { IBOutlet UITextField *emailField; IBOutlet UITextField *passswordField; IBOutlet UIButton *loginButton; IBOutlet UIActivityIndicatorView *loginIndicator; IBOutlet UIPickerView *pickerView; NSMutableArray *sites; } @property (nonatomic, retain) UITextField *emailField; @property (nonatomic, retain) UITextField *passwordField; @property (nonatomic, retain) UIButton *loginButton; @property (nonatomic, retain) UIActivityIndicatorView *loginIndicator; @property (nonatomic, retain) UIPickerView *pickerView; @property (nonatomic, retain) NSMutableArray *sites; -(IBAction) login:(id) sender; @end </code></pre> <p><strong>LoginViewController.m</strong> #import "LoginViewController.h" #import "myECGViewController.h"</p> <pre><code>@implementation LoginViewController @synthesize emailField, passwordField, loginButton, loginIndicator, pickerView, sites; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } //NSLog(@"%@", sites); return self; } - (void)dealloc { [super dealloc]; } - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } #pragma mark - View lifecycle - (void)viewDidLoad { [super viewDidLoad]; sites = [[NSMutableArray alloc] init]; [sites addObject:@"Canada"]; [sites addObject:@"USA"]; //[pickerView selectRow:1 inComponent:0 animated:YES]; // Do any additional setup after loading the view from its nib. } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return NO; } -(IBAction) login:(id) sender { loginIndicator.hidden = FALSE; [loginIndicator startAnimating]; loginButton.enabled = FALSE; // Do login NSLog(@"E:%@ P:%@", emailField.text, passswordField.text); } -(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView { return 1; } -(NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { NSLog(@"%@ : %d", [sites objectAtIndex:row], component); return [sites objectAtIndex:row]; } - (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component { NSLog(@"numberOfRowsInComponent: %d : %d", [sites count], component); return [sites count]; } -(void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { NSLog(@"Selected: %@", [sites objectAtIndex:row]); } @end </code></pre> <p>Any help is appreciated.</p>