ios
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; }
Related Links
Updating a delivered notifications ios 10
Adding Shadow to a UIBarButton
Use of unresolved identifier 'present' - the present method doesn't work anymore
OpenCV and LibPNG conflict
Disable swipe in one direction for UICollectionView
Is Google supports offline map in iOS? [duplicate]
Swift - Toggling CollectionView cells to toggle items in an Array
Remove optionals from codegen generated NSManagedObject subclass
How to use one button to add scores for different integers (swift3)
iOS camera freezes when previewing video when there is a camera overlay
Objective C: Member reference base type 'float' is not a structure or union error
How to get the closest time to current time from an array of dates ? iOS, Swift 3
Getting the value of a TypeSwitch
Podio SDK - Retrieve multiple image files
How to define a class and module for a view created programmatically in swift
iOS device unable to access an iCloud account crated by another iOS device