I want to make multiple UIPicker with following requirements -
Make Multiple UIPicker (let's call them Picker1 and Picker2)
Value of Picker2 should automatically change based upon value of Picker1 (for instance I Picker1 has countries and Piker2 should display cities in that country)
also I would like to change the data in UIView based upon the value selected from Picker1 and Picker2 (lets say we select "UK" and city as "London" then UIView should talk only about "places to visit in london"
I know it sounds like lot of asking - your help would be highly appreciated, Thanks in advance.
First, your ViewController(the one with the picker) should implement the UIPickerViewDelegate.
You should than use this method:
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
It gets called every time you change a the selected row on any of the components of your picker.
For example when this gets called, you should change the UIView element to the appropriate value.
This is also the moment to reload Component2 (or whatever you want to call it) of your picker like this.
[picker reloadComponent:2];
or
[picker reloadAllComponents];
Related
I need to perform some code when the user stop scrolling the picker, in other way, when the picker stop scrolling. The logic i want to follow is, once the picker stop scrolling, i get the current value and i do some database queries basing on that value.
In the picker view documentation, i don't see a delegate method that can help on such task. Any thoughts? thanx in advance.
whenever you scroll the picker view, didSelect delegate method call at the end of scroll
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
NSLog(#"Selected %i. ", row);
/// do it here your queries
}
try with above example and check your console
The delegate class has a method pickerView:didSelectRow:inComponent:, that you can use to detect the selected row.
hi
I am working on an iPhone app & i have to show some thing on a pickerview after receiving a response from socket, Methods of PickerView are check when application is going to be load. in my app i have to load PickerView on a button click.
After getting response in an array, When i click on button its shows a pickerview but empty. :(
SO can any body tell me how to reload the pickerview like tableView.
Thanx in advance
you could use either reloadAllComponents to realod all the component or reloadComponent to a zero-indexed number identifying a component of the picker view.
[myPickerView reloadAllComponents];
[myPickerView reloadComponent:IndexOfReloadComponent];
Read UIPickerView documentation
You can use below code, I hope it's work
[obj_Picker reloadAllComponents];
Call -reloadComponent: or -reloadAllComponents (methods on UIPickerView).
Quote:
You can dynamically change the rows of a component by calling the reloadComponent: method, or dynamically change the rows of all components by calling the reloadAllComponents method. When you call either of these methods, the picker view asks the delegate for new component and row data, and asks the data source for new component and row counts. Reload a picker view when a selected value in one component should change the set of values in another component. For example, changing a row value from February to March in one component should change a related component representing the days of the month.
Use this method - (void)reloadAllComponents of the UIPickerView class.
I'm still very new to cocoa touch so please excuse any terminology that I may have got wrong.
I have a bunch of images in my bundle consecutively named image0.png, image1.png etc...
I have a picker in a viewcontroller and an instance variable that keeps track of the current row.
When a user clicks a button I want to be able to create a uiImageView object (and first test whether the view already exists) based on the row number, ie: uiImageView *imageView1 for row1.
Is this possible or would it just be easier to create a line of code for each possible case?
I hope this makes sense, and thanks in advance for anyone that can shed any light!
Why not just create one UIImageView in Interface Builder and then swap out the image it's displaying depending on your picker index?
Implement:
- (void)pickerView:(UIPickerView *)pickerView
didSelectRow:(NSInteger)row
inComponent:(NSInteger)component
{
[imageView setImage:[imagesArray objectAtIndex:row]];
}
Where imageView is an instance variable (IBOutlet) connected to the image view control in Interface Builder.
Ok, that makes sense.
I think what I was trying to do was take lazy loading to the extreme by only creating the uiImage object and the uiImageView object the first time it was called on from the picker (having clicked the "go" button).
I anticipate having around 40 images that will fill the screen.
Programatically, would this be an acceptable method for this number of images?
Thanks very for the responses guys.
i Have some problem. i have 25 records in my NSMutableArray and i want to display them 5 records at a time when user press Next button then another 5 records to display and when user press back button then previous 5 records to display.
How can i do this any help from you would be great.
Thank You.
Make an ivar in your table view controller that tracks which records you should display. Set the ivar in your Next/Back buttons action method and send [self.tableView reloadData]. Use the ivar in -tableView:numberOfRowsInSection: and -tableView:cellForRowAtIndexPath: to determine how many and which cells to display.
First of all, I recommend against this design. Tableviews on iPhone apps are great to scroll with your fingers, and having buttons like this defeats this. However, I don't know what you're doing, so I'll assume it's cool.
My suggestion is to use slices of the larger array as follows:
- (NSArray *)itemsForPage:(NSUInteger)p {
NSIndexSet *indexes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(5*p,5)];
return [_thatOneLargeArray objectsAtIndexes:indexes];
}
Note that I've refactored this code into a method. Let me know if this is helpful!
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