When move values in uipickerview faster than something went wrong - iphone

I am having a UITextField and replacing iPhone keyboard with UIPickerView having 3 to 4 components in a row, the problem i am facing is that when i move values of 3 or 4 components faster as much as i can the event - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component is fired one, and only value of just one component is updated which was selected at last. How can i fix it ? is there any method other than - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component to overcome this problem?
thanks

problem can be solve using if conditions. like:
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if(component == 0)
{
}
if(component == 1)
{
}
if(component == 2)
{
}
}

Zohaib, if I understand correctly you're scrolling through 3 or 4 components very quickly is it? The method - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component as far as I know is fired when a row is actually selected, i.e. a scroll ends at this particular row and it is therefore 'selected'. So, I'd assume its correct in being called only once. I assume you're not scrolling-then-stopping and doing that several times?

I faced the same problem of having multiple components scrolling at the same time, in the end only one selected value is detected.
I found a solution mentioned by someone in Apple discussion.
- (NSInteger)selectedRowInComponent:(NSInteger)component
Instead of relying on the row component value return by the picker, use above method to find each selected value in your picker and update accordingly.
Hope it helps

This is a problem with iOS 7. I was able to reproduce this in a test app with a picker with only 1 component. The trick is to get the picker going really fast so there's a big bounce at the end (sometimes a double or triple swipe is needed). It only happens about 1 time in 10 and I can't seem to get it to happen on the iPhone. I have however seen it on both the simulator in Xcode 5.0 and my iPad mini with Retina Display running 7.0.6.
https://dl.dropboxusercontent.com/u/36715615/UIPickerViewTest.zip

Related

How to get the mins and secs in UIPickerView as in figure?

How can we achieve such type of selected values to be changed with mins and secs in UIPickerView???
First, you use the pickerView:viewForRow:inComponent:reusingView: data source method to return the "00" label. This is actually a bit tricky, since pickerview will alter the frame of this view to fill the row. That means you have to embed your properly positioned view inside another view, and then return that container view instead.
As for the labels, those are simply UILabel objects that have been positioned correctly and added as subviews of the pickerview itself.
And to get them to update correctly, just change their titles in the pickerView:didSelectRow:inComponent: method.
This is exactly what UIDatePicker is doing.
You should implement UIPickerViewDelegate Protocol and UIPickerViewDataSource Protocol.
In method - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component just return needful title.
You can also add delegator on valueChanged event of UIPickerView. And each time your value changed you can reload all visible rows and set labels mins and secs at right positions.
Oooor you can just add subview with 2 UILabels over the black line.
Oooor you can add subview with black gradient line with labels mins and secs.
Then using method : - (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component you can set appropriate width of your columns.

UIPickerView for iPhone

I am creating a Unit Converter app using a pickerview with three components and a plist. The first component is category component and the remaining are units components. What i need is when i select an item in category component the remaining two components should get the values regarding that particular component. For this to work how i need to take a plist? Can some one help me on this?
First your que. is not pretty clear, I mean , do u fetching the data using webservice or what...? plist..it is not necessary
all stuff that u've to play with delegates methods for e.g.
1)
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
}
tells how many component u want to add.like categories/unit1/unit2/bla..bla...bla
2)
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger) component
{
}
tells what u hv to do with rows.
3)
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
}
thats it
I don't understand what you mean with the plist... But:
For the context dependent presentation of the two other values you should have a look into pickerView:didSelectRow:inComponent: of UIPickerViewDelegate. There you can react of the change of the value in the first component.

UIPickerView disable column

How can i disable UIPickerView column?
I want to disable only one column of picker. Lets say i have picker with 3 column and i want to disable second column.
There are a couple options here.
1) Capture interaction with the second column and override it.
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component;
This method can be implemented to simply go back to where it was before the selection. However, they will still be able to interact with the second column.
2) Simply remove the column from the picker.
I believe this is the best option. Have some boolean 'showSecondColumn'. Then, in:
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
you can simply check your little flag and return the appropriate number. UIPickerView has a method: reloadAllComponents
Good luck!
It seems there is no way to disable column. I solved(not best solution) like this:
get column as "image" (snapshot)
grayscale "image"
set "image view" user interaction enabled
add "image view" to picker as subview
If there is any better way it would be great.

Just numbers in a UIPickerView?

Is there a way to have a UIPickerView just have escalating numbers to infinity?
Haha. Just kidding, but seriously, I want just a bunch of numbers going up, but I don't want to have to hard-code it all.
Thanks in advance!
I'm pretty sure this can be done with some cleverness (a custom integer class that supports arbitrarily large numbers, and periodically "rolling over" to a higher set of numbers once the user has scrolled through all NSIntegerMax rows (i.e. when the user scrolls to row NSIntegerMax you programmatically scroll them back to row 0 and display "row + NSIntegerMax" instead of just "row"). As they scroll through repeatedly you change it to "row + NSIntegerMax * 2", etc.
Obviously you also have to handle them changing directions are some point.
But I suspect that's what fancier than what you're looking to do. In this case you just want to add these lines of code to your View Controller:
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return NSIntegerMax;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return [NSString stringWithFormat:#"%d", row];
}
Then double click on the View nib file (the *.xib file) to open it in Interface Builder, and connect the "data source" outlet to the "File Owner" (the View Controller). That will get you as many integers as I could ever imagine someone scrolling to.
Have a look at this question. It is a variation on your problem.
You could just use a UIStepper. I know you asked about UIPicker but do you really need to use that class or were you using it to explain what kind of thing you wanted

UIPickerView disable row selection

I want to disable the selection of certain rows in my UIPickerView. Like in the Coundown timer, where you try to choose 0, it doesn't let you and slips back up to 1. Or how you can limit the date in the Date Picker...
How do a disable rows in a UIPickerView?
In UIPickerView delegate method
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
you can check if this selection is valid and scroll to the appropriate row if it is not (using pickerview's
- (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated
method.)
It looks that standard Clock application works this way.