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

Custom Callout - ViewDidLoad - Swift
Xcode autolayout - dynamic constraints
How to solve the error “:37: parser error : EntityRef: expecting ';'” in Xcode, Objective-C
iOS new view not appearing and/or old view not disappering
How to place textfield position using tap gesture
UICollectionView must be initialized with a non-nil layout parameter. error in swift with UICollectionView
How to rotate custom marker image on google map objective c
Determine “nil” value in JSON
How to Speed up the audio Playing in MpMoviePlayerController
share extension in ios 8 with objective c
Implementing pixel-perfect background images in different orientations
iAP buy button with price tier text
Segmentation fault OR Stacktrace when using UIView with message forwarding feature of Objective-C
How to get the String Value in JSON
Add TapGestureRecogniser to UITextView
Navigation title not working properly

Categories

HOME
sbt
ssl
ssl-certificate
load
streaming
binary-search
windows-10-desktop
oracle-ucm
syswow64
data-annotations
jmespath
teamcity-9.0
jpos
similarity
microphone
digital-logic
vnc
pymysql
breakpoint-sass
panel-data
lync
google-shared-contacts
doctrine-odm
disqus
psychopy
procobol
linear
textangular
qmenubar
gulp-babel
recurrence
dump
fasta
view-source
easyhook
asp.net-mvc-custom-filter
db2400
agile-processes
android-alertdialog
mailcore2
rails-console
activity-diagram
ng-annotate
cufft
visual-build-professional
vlc-android
android-number-picker
intrinsics
flotr2
training-data
occam-pi
membership
actioncable
appv
translate3d
solr-boost
odoo
movie
tab-delimited
gnat
mui
httpservice
android-menu
iphone-privateapi
before-save
subdirectory
team-explorer-everywhere
bunny
custom-titlebar
delphi-2009
jxta
libavcodec
simpleaudioengine
onejar
location-client
sugar.js
wow64
rcu
xcode4.2
pixelsense
j#
sdl.net
codi
nstreecontroller
eclipse-tptp
xlink
sqlprofileprovider
metaphone

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