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

MFMessageComposeViewController not returning to application after send message ios9
This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes.
Writing a flood-fill method in Swift
Facebook Graph API query for latest album from page
Options for sending data to server/retrying requests in background
xcode, ios, Help Image Freezes, Not Moving
Hidden property cannot be changed within an animation block
MPmoviePlayer going black after updating to IOS 9 ( swift )
Run custom script after iOS app is signed in XCode
Video frames fill only 1/4 of the view - GL
How can I change the image in the detail view to access the master view
Can I use swift 1.2 with iOS 9? [closed]
Why same nsmutablearray gives me valid value and a null on different functions used
Capture location in all states app
Does prefix works correctly in Xcode 7 beta 6?
Ios Push notification : Null would like to send you notifications

Categories

HOME
ios
simulated-annealing
copy
stripe-payments
ionic3
cross-domain
range
push
w3.css
union
scale
atmelstudio
durandal-2.0
html-email
thrift
lexikjwtauthbundle
django-autocomplete-light
easendmail
profiling
bitcode
shape
azure-redis-cache
sql-server-2014-express
ruamel.yaml
svn2git
pymysql
scom
svgpanzoom
webcenter
doctrine-odm
edit-distance
executorservice
delete-row
ecmascript-4
apartment-gem
sinon
google-slides
linear
edeliver
textangular
sweet.js
android-calendar
sql-mode
fasta
ietf-netconf
itertools
liclipse
tastypie
jeditorpane
postmark
surroundscm
mit-scheme
coldfusion-11
data-fitting
texture2d
ng-annotate
airplay
parsoid
wand
python-dragonfly
appv
kindlegen
ppl
byte-order-mark
gitattributes
llvm-gcc
java-client
nolio
information-schema
epoll
linguistics
team-explorer-everywhere
pkcs#10
tinkerpop-frames
textselection
jqgrid-php
xml.modify
mod-python
transport-stream
shift
nsusernotificationcenter
nsimageview
mainwindow
kmz
asp.net-authentication
google-chrome-frame
layout-manager
lungojs
maven-bundle-plugin
ria
objcopy
stumbleupon
websolr
gemstone
soapheader
blackberry-os-v5
orthographic
treetop
jdic
spquery
custom-protocol
cracker

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