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 to get the invoke arguments for an Adobe Air iOS app?
Navigate to a View Controller from a class which is not a View Controller
DismissViewControllerAnimated is not working
Restore InApp purchase using swift, iOS
How to change [[NSBundle mainBundle] preferredLocalizations];?
UITableView only updating on scroll up, not down
Post json array to web service not working
Why does LambdaExpression.Compile() work on iOS (Xamarin)?
Build failed--attribute must have a defined type
Firebase iOS query not ordering as expected
Swift code compiles fine on iOS, gives warning on OSX: Enum case pattern cannot match values of the non-enum type 'SKPaymentTransactionState`
Data does not get updated on the table view from one view to the next
In swift, when one property has no default value, the default values held by other properties become useless?
How can I loop through the coordinates of a CGPath?
AVAsset not recognising NSURL - Crashing - iOS
Size class specifically for portrait 3.5 inch (iPhone 4S) XCode 6?

Categories

HOME
odoo-10
sqlite
logstash
identityserver4
xaml
copy
load
typeahead.js
datetime
saml
runtime-error
ibm-midrange
documentation
square-connect
calayer
graphengine
pouchdb
aac
zend-expressive
accumulo
watchservice
appcelerator-alloy
hp-alm
software-distribution
jpos
broker
jcrop
robotium
ratchet-2
google-oauth2
yii1.x
reformatting
silverlight-5.0
matterjs
spring-websocket
azure-app-service-envrmnt
folly
xaf
symfony-process
csr
subscription
ms-jet-ace
laravel-routing
paypal-webhooks
ice
autogen
lapply
ultratree
xceed
submission
oracle-policy-automation
selenium2library
groupbox
jongo
schematiq
screen-capture
ospf
python-2.3
julian
error-log
boost-coroutine
genexus-gam
smarty2
windows-universal
sql-server-ce-3.5
mks
applicationstate
setattribute
cvs2git
jasmin
liferay-hook
laravel-validation
sendto
first-class-functions
dojo.gridx
jquery-backstretch
couchrest
bochs
gora
chomsky-hierarchy
firebird2.1
rcu
adlds
google-chrome-frame
source-highlighting
uptime
slimbox
northwind
dynamic-usercontrols
symfony-2.2
mixing
undeclared-identifier
sticky-footer
httpcontext.cache
dired
replay
pong
paredit
syncml
keylogger
scramble
msn-messenger
run-length-encoding
68hc11
help-authoring

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