rkmakwana rkmakwana - 1 year ago 106
iOS Question

UIPickerView content flowing unexpectedly

I am using

in my app. But both the controls are showing weird behaviour. When I scroll the content in the picker, it flows outside the picker and does not scroll as it is supposed to. My implementation is as below.

sexArray = @[@"Male", @"Female"];
UIPickerView *picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 50, 100, 150)];
[picker setDataSource: self];
[picker setDelegate: self];
picker.showsSelectionIndicator = YES;
genderTF.inputView = picker;


-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
return sexArray.count;

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 1;

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row
forComponent:(NSInteger)component reusingView:(UIView *)view {
UILabel *retval = (UILabel*)view;
if (!retval) {
retval = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 100, [pickerView rowSizeForComponent:component].height)];

retval.font = [UIFont fontWithName:@"SourceSansPro-Regular" size:15.0f];
retval.minimumScaleFactor = 0.6;
[retval setTextAlignment:NSTextAlignmentCenter];
retval.text = [sexArray objectAtIndex:row];

return retval;

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
[genderTF setText:sexArray[component]];

When the same code is used in another app (for testing), it works as expected.

Editing began

When content Scrolled

Answer Source

Turns out that the implementation was correct on my part. The problem was because of a third party library.

I was using a pod SLPagingView in my project which made the `UIPickerView' act weird. I couldn't find a solution and ended up in replacing the pod with similar pod.

Details link