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

Categories

HOME
f#
xcode8
svg.js
logback
vsix
antlr4
spi
mvvm-light
android-bluetooth
entity
autofac
calayer
asciidoc
highlight
yii2-advanced-app
facebook-opengraph
ellipse
imp
amadeus
prerender
ssrs-2008
textmatebundles
advantage-database-server
background-subtraction
confidence-interval
vnc
pdfa
simple-html-dom
phonegap-desktop-app
ocean
breakpoint-sass
react-redux-form
vue-router
presto
macvim
uistoryboardsegue
consistency
automata-theory
php-5.5
project-centennial
hostapd
opal
smartbanner
g-wan
billing
jce
zbar
netbeans-7
tastypie
lapply
wxhaskell
nsd
setwindowshookex
amazon-dynamodb-streams
directsound
webtrends
cufft
gcloud-java
android-popupwindow
docklight
wgs84
json4s
avalonedit
crowdflower
omap
gitattributes
vendor
misra
physx
office-2010
controlsfx
ash
jquery-backstretch
xml.modify
css3pie
onejar
apache-commons-dbcp
chomsky-hierarchy
scrollpane
guice-servlet
documentviewer
mysql-backup
sticky-footer
ms-access-97
cellphone
treetop
xoom
program-transformation
non-relational-database
anemic-domain-model
geneva-framework
sqlitemanager

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