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

How do I remove the opacity from UIPickerView on the unselected rows
How long Apple will keep trying charge for failed auto renewable subscription?
How do I paste an image programmatically with Swift?
Real-time data from Raspberry Pi to iPhone
Delete items from project podfile
Wrong area calculation objective-c?
Swift Image masking
UIView center property is giving unexpected result
Nordic nrf51822 - Why doesn't it read all data?
XCode error when trying to run Unity3D app
UIStackView - Three arranged subviews with relative widths
Run a task when the application is in background Ionic and Native Approach
Set custom nav back button with multiple navigation controllers
iOS Accessibility for CollectionView in a TableViewCell
Subtracting numbers as Objects - Objective C
Xcode UITest - Unable to find buttons in a Cell containing Key Value Pairs

Categories

HOME
jsp
python-3.5
fpdf
gluon
active-directory
restsharp
sony
py.test
akka.net
windows-10-desktop
gcov
telnet
pie-chart
asciidoc
light-inject
luci
condor
records
html-email
zap
contains
jruby
rtp
rgdal
wso2cep
liferay-aui
shape
iteration
structure
desktop-app-converter
point-cloud-library
webfocus
shinydashboard
solarwindslem
python-behave
dapper-fastcrud
pymysql
angular2-databinding
vue-router
nib
advanced-installer
ecmascript-4
sinon
ibm-wcm
visualsvn-server
azure-management-api
using
tern
xargs
qmenubar
program-slicing
php-deployer
pulseaudio
sql-insert
name-mangling
asyncsocket
unityscript
facebook-canvas
curly-braces
gcloud-java
screen-capture
wand
post-processor
android-gpuimageview
maven-cargo
ppl
cvc4
structured-programming
alienvault
access-log
nolio
sendto
dojo.gridx
cellular-automata
jquery-backstretch
populate
serverside-javascript
yourls
preon
execcommand
semantic-markup
google-chrome-frame
python-dateutil
impdp
hamlc
hogan.js
datadesign
dynamic-usercontrols
cakephp-2.1
rc-shell
oledbcommand
noindex
expressionvisitor
process.start
duplicate-data
springboard
plinqo
mkreversegeocoder
jquery-1.3.2
apache-config
project-settings
gedcom
variable-names
database-dump
case-tools

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App