Reputation: 1342
I want to display PickerView when I click the button. I have a view which has 3 buttons. In the corresponding actions to the buttons, I have alloc'ed and init'ed the pickerView as follows: pickerView = [[UIPickerView alloc]init]; Also I have added the PickerView to the Subview as follows: [self.view addSubview:pickerView];
I've also subclass'ed my class with UIPickerViewDataSource and UIPickerViewDelegate as follows: MyClass : UIViewController
By NSLoging i saw that PickerView DataSource and Delegate methods are not getting called. When I click(TouchUpInside) the button, the view shows up pickerView with origin=(0,0) which should be at bottom and pickerView appears total Black. I fixed the PickerView's frame by using: pickerView.frame = CGRectmake(0,180,320,260);
I googled to check when the pickerView's DataSource and Delegate method are called but I couldn't find the proper answer.
I also tried the "hidden" property here as follow: In viewDidLoad method: pickerView.hidden = YES; In the method which is called after clicking button: pickerView.hidden = NO;
Help me please. I'm new to Objective C.
Upvotes: 1
Views: 3403
Reputation: 170849
If you create your picker programmatically - did you actually set its delegate and dataSource?
// Assuming that delegate and data source is controller where picker is created
pickerView.delegate = self;
pickerView.dataSource = self;
Upvotes: 4