In the help document, it says that:
Calling this method causes the picker view to query the delegate for new data for the given component.
I added some breakpoints at:
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
when I call the reloadComponent method but none of them were called. What is the problem?
You need to set the dataSource property of the pickerView to an instance of a class that implements the UIPickerViewDataSource protocol.
I think the documentation is referring to a "delegate" as in the software engineering design pattern of delegation, as opposed to the property delegate of the class which is probably a little misleading.
Related
I need to know how to firing picker object after I click a button. So i need to know how to do that one.
Have you implemented UIPickerViewDelegate didSelectRow delegate method,
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
I handle clicks to UIPickerView rows with a regular method
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
but it works only for non-current rows. My problem is that I need to get taps on the already selected (current) row also. Any ideas or workarounds for didSelectRow? Thanks.
You could put a clear button over each row and handle touches from it like any other button.
How does one code this scenerio in iphone sdk?
In an expense app, when you want to add an expense, this view comes up.
After selecting "Clothing," another view slides up with a UIPickerView control that has a "done" button which will dismiss the UIPickerView. Below is a screen shot after hitting "Clothing."
I'm trying to figure out how one would slide up the UIPickerView half way up the screen with a "done" button on top of the "New Expense" view?
thank you in advance!
Use CoreAnimation and make the UIView with move from bottom to top.. and change the hidden property to true from false when required and vice versa..
Multiple UIViews can be nested as required take advantage of this to achieve what u need
You implement the UIPickerDelegate, then implement the methods that belongs to the UIPickerView.
So your interface file must contain this:
#interface YourViewController : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource> {
Your viewController them implements these, or more, methods:
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component;
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
t´You would then instantiate the picker, set its delegate and all other properties you need it to conform to.
You could then hook up a "listener" for keeping track on when it changed.
[datePicker addTarget:self action:#selector(didChangeDate) forControlEvents:UIControlEventValueChanged];
A good place to start is the UICatalog example from the Apple developer site.
This has a lot of Picker code and a bunch of other stuff that could help getting in the mindset Apple uses for building stuff with UIElements.
Hope it helps:) it is a large subject.
This post helped me; might help others: http://sdhillon.com/animated-uipickerview
I have a UIPickerView, in it's delegate I'm trying to customize the view for a row. I'm using the 3.1 SDK.
So in the delegate I have:
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
// view.backgroundColor = [UIColor redColor];
return view;
}
From the apple docs:
If the previously used view (the view parameter) is adequate, return that. If you return a different view, the previously used view is released. The picker view centers the returned view in the rectangle for row.
When I run this, my UIPickerView control doesn't have any items in it, and after a short while crashes.
When I remove this particular method (which is optional for the delegate), I can see the labels I set via the titleForRow method, and it will no longer crash.
I'm pretty new to cocoa (and cocoa-touch), I'm not sure the view.backgroundColor thing will work, but even when returning the unmodified old view (which I must do anyway for most rows) crashes my app.
Am I doing something wrong?
Yes, you implement either –pickerView:titleForRow:forComponent: or –pickerView:viewForRow:forComponent:reusingView:, but not both. What is happening is that it is not calling your –pickerView:titleForRow:forComponent: because it is using your –pickerView:viewForRow:forComponent:reusingView:. You are returning the reusingView: parameter, but that is nil the first time, because there was no "previously used view" for that row.
I am trying to create a Dialog Box in which contains a UIPickerView. I can get it to work without the Subview tied around it but I always end up with an Uncaught error. Any help?
Well apparently I fixed by messing with this method -(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component