While using picker view - ios

enter image description here $ The data of assigned array is not showing in the pickerView. What mistake I am doing as I haven't being able to identify my mistake.
Its .m file code:
// PickerViewController.m
// dropDownButtonTry
//
#import "PickerViewController.h"
#interface PickerViewController ()
{
NSArray *genderArray;
NSArray *cityArray;
NSArray *currentArray;
UITextField *currentTextField;
}
#end
#implementation PickerViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
cityArray = [[NSArray alloc]initWithObjects:#"Delhi",#"Mumbai",#"Chennai", nil];
genderArray = [[NSArray alloc]initWithObjects:#"Male",#"Female",#"Transgender", nil];
self.pickerView.hidden = YES;
self.btnDoneOutlet.hidden = YES;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[self.view endEditing:YES];
}
//Needed to prevent keyboard from opening
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
currentTextField = textField;
if (textField == self.textFieldGenderOutlet) {
currentArray = genderArray;
}
if (textField == self.textFieldCityOutlet) {
currentArray = cityArray;
}
// do here everything you want
NSLog(#"Pressed on TextField!");
self.pickerView.hidden = NO;
self.btnDoneOutlet.hidden = NO;
[self.view endEditing:YES]; // Hide keyboard
NSLog(#"****current array**** %#",currentArray);
return NO;
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return [currentArray count];
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
[currentTextField setText:[currentArray objectAtIndex:row]];
}
-(NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [currentArray objectAtIndex:row];
}
- (IBAction)textFieldGenderAction:(id)sender {
self.pickerView.hidden = NO;
self.btnDoneOutlet.hidden = NO;
}
- (IBAction)btnDone:(id)sender {
self.pickerView.hidden = YES;
self.btnDoneOutlet.hidden = YES;
}
- (IBAction)textFieldCityAction:(id)sender {
}
#end

You need to reload picker view :
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
currentTextField = textField;
if (textField == self.textFieldGenderOutlet) {
currentArray = genderArray;
}
if (textField == self.textFieldCityOutlet) {
currentArray = cityArray;
}
// do here everything you want
NSLog(#"Pressed on TextField!");
self.pickerView.hidden = NO;
self.btnDoneOutlet.hidden = NO;
[self.thePicker reloadAllComponents];
[self.view endEditing:YES]; // Hide keyboard
NSLog(#"****current array**** %#",currentArray);
return NO;
}

currentArray is assigned value in textFieldShouldBeginEditing but it is not initialized anywhere in your code.
Just initialize currentArray in viewDidLoad like below:
currentArray = [NSArray new];

Related

iOS:Subclassing UIPickerView not loading in the main view

I'm trying to subclass UIPickerView but is not loading in the main view.
Here is my code:
//Picker.h:
#interface Picker : UIPickerView
- (id)initWithFrame:(CGRect)frame;
//Picker.m:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
}
return self;
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
return 3;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return #"bla";
}
This the code on my viewController:
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:YES];
self.myPicker = [[Picker alloc] initWithFrame:self.view.frame];
[self.view addSubview:_myPicker];
}
Any of you knows why the picker is not loading on my view?
I'll really appreciate your help.
First, add <UIPickerViewDelegate, UIPickerViewDataSource> in header of Picker.h.
Then, assign delegate to your own Picker object.
-(id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.delegate = self; // <-- add this line
}
return self;
}

Using UIPickerView multiple times. iOS Objective-C

I'm a beginner in iOS Objective-C programming so first of all - sorry for being silly.
I'm using UIPickerView to fill UITextField and it works perfectly for the first use.
photo
Lets assume that user made a mistake using pickerview for the first time. He wants to correct this and opens the same pickerview again. Pickerview is empty.
photo
Also okayButton is missing. What am I doing wrong?
Here's my code:
#import "LoginViewController.h"
#interface LoginViewController ()
#end
#implementation LoginViewController
- (void)viewDidLoad {
[super viewDidLoad];
marksArray =[[NSMutableArray alloc] init];
fuelTypeArray =[[NSMutableArray alloc] init];
inputArray =[[NSMutableArray alloc] init];
marksArray = [NSMutableArray arrayWithObjects:#"Alfa Romeo", #"Aston Martin", #"BMW", #"Cadillac", #"Chevrolet", #"Chrysler", #"Citroen", #"Dacia", #"Daewoo", #"Dodge", #"Ferrari", #"Ford", #"Honda", #"Hummer", #"Hyundai", #"Infiniti", #"Jaguar", #"Jeep", #"Kia", #"Lamborghini", #"Lancia", #"Land Rover", #"Lexus", #"Maserati", #"Mazda", #"Mercedes-Benz", #"Mini", #"Mitsubishi", #"Nissan", #"Opel", #"Peugeot", #"Polonez", #"Pontiac", #"Porshe", #"Renault", #"Rover", #"Saab", #"Seat", #"Skoda", #"Smart", #"Subaru", #"Suzuki", #"Toyota", #"Volkswagen", #"Volvo", nil];
fuelTypeArray = [NSMutableArray arrayWithObjects:#"Benzyna", #"Benzyna+LPG", #"Diesel", #"Elektryczny", #"Hybryda", nil];
okayImageView.hidden = true;
okayButton.hidden= true;
//makes fuelTypePickerView as input console for markTextField
fuelTypePickerView.hidden = true;
fuelTypePickerView = [[UIPickerView alloc] init];
fuelTypePickerView.delegate = self;
fuelTypePickerView.showsSelectionIndicator = YES;
fuelTypeTextField.inputView = fuelTypePickerView;
//makes markPickerView as input console for markTextField
markPickerView.hidden = true;
markPickerView = [[UIPickerView alloc] init];
markPickerView.delegate = self;
markPickerView.showsSelectionIndicator = YES;
markTextField.inputView = markPickerView;
// scrolling login view controller
[scroller setScrollEnabled:YES];
[scroller setContentSize:CGSizeMake(320, 615)];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
// returns the number of 'columns' to display.
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
okayImageView.hidden = false;
okayButton.hidden= false;
return 1;
}
// returns the # of rows in each component..
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
if([pickerView isEqual: markPickerView]){
return 45;
}else if([pickerView isEqual: fuelTypePickerView]){
return 5;
}else{
return 0;
}
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
if([pickerView isEqual: markPickerView]){
self->inputArray = self->marksArray;
return inputArray[row];
}else if([pickerView isEqual: fuelTypePickerView]){
self->inputArray = self->fuelTypeArray;
return inputArray[row];
}else{
return 0;
}
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if([pickerView isEqual: markPickerView]){
markTextField.text = [inputArray objectAtIndex:row];
}else if([pickerView isEqual: fuelTypePickerView]){
fuelTypeTextField.text = [inputArray objectAtIndex:row];
}
}
-(IBAction) okayButtonPressed:(id)sender{
if(markPickerView.hidden!=YES){
okayImageView.hidden = true;
okayButton.hidden= true;
markPickerView.hidden=YES;
[markTextField resignFirstResponder];
}else if(fuelTypePickerView.hidden!=YES){
okayImageView.hidden = true;
okayButton.hidden= true;
fuelTypePickerView.hidden=YES;
[fuelTypeTextField resignFirstResponder];
}
}
#end
Thanks!
Try adding the following lines in your code
#interface LoginViewController () <UITextFieldDelegate>
then in viewDidLoad
fuelTypeTextField.delegate = self;
markTextField.delegate = self;
Now implement UITextField Delegate in your LoginViewController
-(void)textFieldDidBeginEditing:(UITextField *)sender{
okayImageView.hidden = NO;
okayButton.hidden = NO;
if([sender isEqual:fuelTypeTextField])
{
fuelTypePickerView.hidden = NO;
}
else{
markPickerView.hidden = NO;
}
}
In your Code after click on OK button you are hiding the PickerView, ImageView and Button. But on next time editing the textField you are not unhiding them thats why they are not shown.

PickerView is not showing

I'm trying to bring up a picker view instead of a keyboard to put in a textfield, but my picker view doesn't show.
#import "SettingsViewController.h"
#import "FindClasses.h"
#interface SettingsViewController ()
#property (weak, nonatomic) IBOutlet UIBarButtonItem *saveButton;
#property (weak, nonatomic) IBOutlet UITextField *classTextField;
#property (strong, nonatomic) UIPickerView *picker;
#property (nonatomic, strong) FindClasses *finder;
#property (nonatomic, strong) NSArray *itemsArray;
#end
#implementation SettingsViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSArray *itemsArray = [self.finder findClassesInTimetable];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)presentPicker {
CGRect frame = CGRectMake(0, 40, 0, 0);
UIPickerView *picker = [[UIPickerView alloc] initWithFrame:frame];
picker.delegate = self;
picker.dataSource = self;
// TODO: animate this on screen
[self.view addSubview:picker];
}
- (void)textFieldDidBeginEditing:(UITextField *)textField {
[self presentPicker];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return [self.itemsArray count]; //where items is your array of items
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row inComponent:(NSInteger)component {
return [self.itemsArray objectAtIndex:row];
}
Can someone tell me what I'm doing wrong? I took the example from another Stackoverflow post:
This is how I use UIPickerViews, with sample code:
UIPickerView* genderPicker = [[UIPickerView alloc] init];
genderPicker.delegate = self;
genderPicker.dataSource = self;
After initializing your UITextField (registrationGenderField in my case):
registrationGenderField.inputView = genderPicker;
And then the delegates and dataSources:
- (NSString *) pickerView:(UIPickerView *)pickerView
titleForRow:(NSInteger)row
forComponent:(NSInteger)component {
switch (row) {
case 0:
return #"Gender";
break;
case 1:
return #"Male";
break;
case 2:
return #"Female";
break;
default:
return #"Gender";
break;
}
}
- (void) pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
switch (row) {
case 0:
registrationGenderField.text = #"";
break;
case 1:
registrationGenderField.text = #"Male";
break;
case 2:
registrationGenderField.text = #"Female";
break;
default:
registrationGenderField.text = #"";
break;
}
}
- (NSInteger) numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
- (NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return 3;
}
Hope it helps you
- (void)presentPicker {
UIPickerView *picker = [[UIPickerView alloc] init];
picker.delegate = self;
picker.dataSource = self;
// TODO: animate this on screen
classTextField .delegate = self;
classTextField.inputView = picker;
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
[textField becomeFirstResponder];
return YES;
}
you just have to alloc init your pickerview;
and set its delegate to self and also add uipickerviewdelegate and datasource in .h file
than in textfieldbegin editing add [textField setInputView:picker];
also implement textfieldshouldreturn

Not able to use two UIPickerView in the same Controller

I'm trying to use more than two UIPickerViews together in one ViewController. Each UIPickerView has different data array. I am using interface builder to link the pickers up. What I want is, after button click, my PickerView will show up and user can select the data from it.That selected data will come in the text field. It is working fine for first PickerView but when I click for the second PickerView, the value is coming from first array and I am not able to write condition. Here's all my code:
.h file
#import <UIKit/UIKit.h>
#interface Tabbar2ViewController : UIViewController<UITextViewDelegate,UITextFieldDelegate,UIPickerViewDataSource,UIPickerViewDelegate>{
IBOutlet UIPickerView *genderPickerView;
IBOutlet UIPickerView *pickerViewoption;
IBOutlet UIButton *BrandPickerBtn;
IBOutlet UIButton *genderPickerfBtn;
NSArray *brands;
NSArray *gender;
BOOL isCheckedpickerView;
IBOutlet UILabel *BrandLabelfield;
IBOutlet UILabel *GenderLabelfield;
}
- (IBAction)action:(id)sender;
- (IBAction)genderAction:(id)sender;
#property(nonatomic,retain)NSArray *brands;
#property(nonatomic,retain)NSArray *gender;
#end
.m file
#import "ttViewController.h"
#interface ttViewController ()
#end
#implementation ttViewController
#synthesize countries,size,brands,gender,activity,condition,color;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
isCheckedpickerView=FALSE;
pickerViewoption.hidden=YES;
genderPickerView.hidden=YES;
activityPickerView.hidden=YES;
conditionPickerView.hidden=YES;
sizeandquantityPickerView.hidden=YES;
BrandLabelfield = [[UILabel alloc] initWithFrame:CGRectMake(20, 812, 253, 35)];
BrandLabelfield.textColor = [UIColor lightGrayColor];
BrandLabelfield.text=#"Brand";
BrandLabelfield.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:#"header_01.png"]];
BrandLabelfield.font = [UIFont fontWithName:#"Open Sans" size:14];
[tabView1 addSubview:BrandLabelfield];
//GenderTextfield with Label //
GenderLabelfield = [[UILabel alloc] initWithFrame:CGRectMake(20, 865, 253, 35)];
GenderLabelfield.textColor = [UIColor lightGrayColor];
GenderLabelfield.text=#"Gender";
GenderLabelfield.font = [UIFont fontWithName:#"Open Sans" size:14];
[tabView1 addSubview:GenderLabelfield];
//ColorTextfield with Label //
ConditionLabelfield = [[UILabel alloc] initWithFrame:CGRectMake(20, 1113, 253, 35)];
ConditionLabelfield.textColor = [UIColor lightGrayColor];
ConditionLabelfield.text=#"Color";
ConditionLabelfield.font = [UIFont fontWithName:#"Open Sans" size:14];
[tabView1 addSubview:ConditionLabelfield];
brands=[[NSArray alloc]initWithObjects:#"Nike",#"Bata",#"Adidas", nil];
gender=[[NSArray alloc]initWithObjects:#"Male",#"Female",#"Unisex", nil];
activity=[[NSArray alloc]initWithObjects:#"BASEBALL",#"BASKETBALL",#"FOOTBALL",#"GOLF",#"RUNNING",#"SKATING",#"SOCCER",#"SPORTS & OUTDOOR",#"TENNIS",#"TRAINING",#"VOLLEY BALL",#"WRESTLING", nil];
// Custom PICKER VIEWS //
pickerViewoption=[[UIPickerView alloc]initWithFrame:CGRectMake(13, 852, 290, 41)];
pickerViewoption.showsSelectionIndicator = YES;
pickerViewoption.delegate = self;
pickerViewoption.dataSource=self;
pickerViewoption.hidden=YES;
[pickerViewoption setBackgroundColor:[UIColor lightGrayColor]];
[tabView1 addSubview:pickerViewoption];
genderPickerView=[[UIPickerView alloc]initWithFrame:CGRectMake(13, 906, 290, 41)];
genderPickerView.showsSelectionIndicator = YES;
genderPickerView.delegate = self;
genderPickerView.dataSource=self;
genderPickerView.hidden=YES;
[genderPickerView setBackgroundColor:[UIColor lightGrayColor]];
[tabView1 addSubview:genderPickerView];
activityPickerView=[[UIPickerView alloc]initWithFrame:CGRectMake(13, 954, 290, 41)];
activityPickerView.showsSelectionIndicator = YES;
activityPickerView.delegate = self;
activityPickerView.dataSource=self;
activityPickerView.hidden=YES;
[activityPickerView setBackgroundColor:[UIColor lightGrayColor]];
[tabView1 addSubview:activityPickerView];
pickerViewoption.tag=1;
genderPickerView.tag=2;
activityPickerView.tag=3;
BrandPickerBtn.tag=000;
genderPickerfBtn.tag=111;
activityPickerBtn.tag=222;
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 1;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row
forComponent:(NSInteger)component{
NSString *string;
if (pickerViewoption.tag==1) {
[tabView1 addSubview:pickerViewoption];
string=[self.brands objectAtIndex:row];
}
else {
[tabView1 addSubview:genderPickerView];
string=[self.gender objectAtIndex:row];
}
else if (genderPickerView.tag==2){
[tabView1 addSubview:genderPickerView];
string=[self.gender objectAtIndex:row];
}
else if (activityPickerView.tag==3){
[tabView1 addSubview:activityPickerView];
string=[self.activity objectAtIndex:row];
}
return string;
}
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row
inComponent:(NSInteger)component {
if (pickerViewoption.tag==1){
BrandLabelfield.text=#"";
BrandLabelfield.text=[brands objectAtIndex:row];
BrandLabelfield.textColor=[UIColor whiteColor];
pickerViewoption.hidden=YES;
}
else if (genderPickerView.tag==2){
GenderLabelfield.text=#"";
GenderLabelfield.text=[gender objectAtIndex:row];
GenderLabelfield.textColor=[UIColor whiteColor];}
else if (activityPickerView.tag==3){
ActivityLabelfield.text=#"";
ActivityLabelfield.text=[activity objectAtIndex:row];
ActivityLabelfield.textColor=[UIColor whiteColor];
}
}
- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component{
if (pickerViewoption.tag==1)
{
return [brands count];
}
else if (genderPickerView.tag==2)
{
return [gender count];
}
else if (activityPickerView.tag==3)
{
return [activity count];
}
return 0;
}
- (IBAction)action:(id)sender; {
if (isCheckedpickerView==FALSE)
{
pickerViewoption.hidden=NO;
isCheckedpickerView=TRUE;
}
else
{
isCheckedpickerView=FALSE;
pickerViewoption.hidden=YES;
}
}
- (IBAction)genderAction:(id)sender {
if (isCheckedpickerView==FALSE)
{
genderPickerView.hidden=NO;
isCheckedpickerView=TRUE;
}
else
{
isCheckedpickerView=FALSE;
genderPickerView.hidden=YES;
}
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Currently you are checking wrong condition in delegate methods, replace following 3 methods in .m file :
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row
forComponent:(NSInteger)component{
NSString *string;
if (pickerView.tag==1) {
[tabView1 addSubview:pickerViewoption];
string=[self.brands objectAtIndex:row];
}
else if (pickerView.tag==2){
[tabView1 addSubview:genderPickerView];
string=[self.gender objectAtIndex:row];
}
else if (pickerView.tag==3){
[tabView1 addSubview:activityPickerView];
string=[self.activity objectAtIndex:row];
}
else {
[tabView1 addSubview:genderPickerView];
string=[self.gender objectAtIndex:row];
}
return string;
}
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row
inComponent:(NSInteger)component {
if (thePickerView.tag==1){
BrandLabelfield.text=#"";
BrandLabelfield.text=[brands objectAtIndex:row];
BrandLabelfield.textColor=[UIColor whiteColor];
pickerViewoption.hidden=YES;
}
else if (thePickerView.tag==2){
GenderLabelfield.text=#"";
GenderLabelfield.text=[gender objectAtIndex:row];
GenderLabelfield.textColor=[UIColor whiteColor];
}
else if (thePickerView.tag==3){
ActivityLabelfield.text=#"";
ActivityLabelfield.text=[activity objectAtIndex:row];
ActivityLabelfield.textColor=[UIColor whiteColor];
}
}
- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component{
if (pickerView.tag==1)
{
return [brands count];
}
else if (pickerView.tag==2)
{
return [gender count];
}
else if (pickerView.tag==3)
{
return [activity count];
}
return 0;
}

UIPickerView selectRow inComponent not working

I have been working on a multi-component picker and I wanted to set the defaults for the various components. The code looks like the following.
#import "MathTablesSelectVC.h"
#interface MathTablesSelectVC ()
#property (weak, nonatomic) IBOutlet UIPickerView *problemDifficultyTypeTable;
#property NSArray *problemDifficulties;
#property NSArray *problemTypes;
#property NSArray *problemTables;
#end
#implementation MathTablesSelectVC
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
NSLog(#"0");
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
NSLog(#"1");
[super viewDidLoad];
_problemDifficulties = #[#"Practice", #"Slow", #"Normal", #"Fast"];
_problemTypes = #[#"Addition", #"Subtraction", #"Multiplication", #"Division", #"Remainders"];
_problemTables = #[#" 0's", #" 1's", #" 2's", #" 3's", #" 4's", #" 5's", #" 6's", #" 7's", #" 8's", #" 9's", #"10's", #"11's", #"12's", #"All"];
}
-(void)viewWillAppear:(BOOL)animated {
NSLog(#"2");
[super viewWillAppear:animated];
[_problemDifficultyTypeTable selectRow:1 inComponent:0 animated:NO];
[_problemDifficultyTypeTable selectRow:0 inComponent:1 animated:NO];
[_problemDifficultyTypeTable selectRow:1 inComponent:2 animated:NO];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
NSLog(#"3");
return 3;
}
-(CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
NSLog(#"4");
if(component == 0) {
return 150.0;
} else if(component == 1) {
return 300.0;
} else {
return 75.0;
}
}
-(CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component {
NSLog(#"5");
return 60.0;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
NSLog(#"6");
if(component == 0) {
return [_problemDifficulties count];
} else if(component == 1) {
return [_problemTypes count];
} else {
return [_problemTables count];
}
}
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
NSLog(#"7");
if(component == 0) {
return [_problemDifficulties objectAtIndex:row];
} else if(component == 1) {
return [_problemTypes objectAtIndex:row];
} else {
return [_problemTables objectAtIndex:row];
}
}
-(void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
NSLog(#"8");
}
-(void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
NSLog(#"9");
}
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
NSLog(#"10");
}
#end
Now this all worked nicely for a while and then it stopped working :(
I then spent the next several hours working out what I'd done wrong.
The answer I stuffed things up when I did some refactoring. I managed to kill the connection between the storyboard and the IBOutlet. Now the nice small, very small, little circle was still there next to the #property it just no longer had a dot in it. As soon as I re-established the connection things started behaving again.
You'll also note a whole bunch of NSLog's and this seems to be the order things are first called in. We get several repeats of some of the numbers as we cycle through the components.
The other thing I broke although I picked that up pretty much straight away were the delegation connections.

Resources