UIPickerView is not scrolling when added to UIScrollView!

I have added UIPickerView to the UIScrollView but now UPickerView is not scrolling. When I add it to the self.view it scrolls smoothly. Here i my code

monthsArray = [[NSArray alloc] initWithObjects:@"Jan",@"Feb",@"Mar",@"Apr",@"May",@"Jun",@"Jul",@"Aug",@"Sep",@"Oct",@"Nov",@"Dec",nil]; UIPickerView *objPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(185,350,100,100)]; objPickerView.userInteractionEnabled=YES; objPickerView.delegate = self; objPickerView.showsSelectionIndicator = YES; [objScrollView addSubView:objPickerView];

I have included the delegete and its methods. have a look on this issue. Thanks in advance.
If I am not clear please tell me.

--------------Solutions-------------

I am using a subclass of UIPickerView for the same purpose, but mine is much simpler:

@implementation ScrollablePickerView

- (UIScrollView *)findScrollableSuperview {

UIView *parent = self.superview;
while ((nil != parent) && (![parent isKindOfClass:[UIScrollView class]])) {
parent = parent.superview;
}
UIScrollView* scrollView = (UIScrollView *)parent;

return scrollView;
}

- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent*)event {
UIScrollView* scrollView = [self findScrollableSuperview];

if (CGRectContainsPoint(self.bounds, point)) {
scrollView.canCancelContentTouches = NO;
scrollView.delaysContentTouches = NO;
} else {
scrollView.canCancelContentTouches = YES;
scrollView.delaysContentTouches = YES;
}

return [super hitTest:point withEvent:event];
}

@end

Works like a charm - at least for me.

UIPickerView is not designed to be scrolled or moved at all. You should place some text field instead and show UIPickerView when user taps on it.

From the UIScrollView class documentation:

Important: You should not embed UIWebView or UITableView objects in UIScrollView objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled.

They don't mention UIPickerView there, but I wonder if it should have been added to that list. It shares in common with the others the characteristic of using touches to scroll things.

I guess this might solve your problem (be sure to check the comments too):

http://www.alexc.me/uiscrollview-and-uidatepicker/153/

Basically you have to set DelaysContentTouches and CanCancelContentTouches to NO on the scroll view, as it steals the touch events from the picker.

I had a similar issue with a UIPickerView nested within a UIScrollView and solved it by subclassing UIPickerView. Changes to DelaysContentTouches/CanCancelContentTouches didn't help, and the other "answers" here that basically say "don't do it" -- well, that's no answer at all! It can be done and you can get a picker to behave within a scrollView.

I answered the following question on subclassing UIPickerView, including some code at the end which may help you:

Responding to touchesBegan in UIPickerView instead of UIView

I've been running into a similar problem. I've got a UIPickerView that I turned horizontal by applying a transform ( which works pretty well), however inside of a scrollview, scrolling only works at the left hand side.

What I think is happening is that the UIPicker looks up it's parent chain to see if there are any gesture recognisers, and sets itself as a delegate, so it can disable gesture recognition further up the chain for touches within it's boundaries, and while the transform changes the visual boundaries, it doesn't change the frame, is it is looking for touches within it's original bounds.

If this isn't what is happening, you could use this to prevent the scroll view stealing your touches.

I'm think I'm going to switch to a custom UISCrollView instead of my transformed UIPickerView.

Category:iphone Time:2011-01-25 Views:0
Tags: iphone

Related post

  • iPhone: UIScrollView not scrolling when adding item via IB 2010-08-31

    I'm trying to make a very simple scrolling page via IB. What I've got is a UIImageView at the top and 2 UIImageViews at the bottom, with a UITextView in the middle. I've disabled the scrolling in the UITextView as I won't the whole page to scroll up

  • adding a UIScrollView as a superview of 2 UITextview made no view can be scrolled 2010-12-27

    i have 2 textview in a viewcontroller. the 1st textview is not editable, but the 2nd is editable. i want to make both of them scroll in the same position and size when the keyboard is appear. I think i have to use UIScrollView as base of both of text

  • How do I scroll a set of UIScrollViews together? 2010-03-02

    Setup: I have a UITableView, each UITableViewCell has a UIScrollView. What I am trying to do is to get all of the UIScrollViews to scroll together, such that when you scroll one of them all of the UIScrollViews appear to scroll simultaneously. What I

  • Detect scrolling in Subclass of UIScrollView 2011-04-15

    Good morning, I've creates a Subclass of UIScrollView and I now want to know when the user is scrolling in my subclass. For that I implemented it like the following: ImageScroller.h @interface UIImageScroller : UIScrollView <UIScrollViewDelegate

  • Detecting tap on the UIImageViews added to UIScrollView 2011-07-12

    I am developing an application in iPhone which has a UIScrollView to which I have added an array of image views (like thumbnails,using loop). The User can scroll either way horizontally and select a particular image. The image on which the user taps

  • UIPickerView crash when scrolling ends, but picker view has been freed already 2011-07-25

    I have a small problem with an UIPickerView. It is part of a class that is displayed as a SemiModalViewController, which can be dismissed (and freed) at any time by pressing an OK button. This class also implements the UIPickerView delegate functions

  • Adding a UIScrollview - Increasing the hight of the scrollview 2012-03-31

    I added a UIViewController, then in the XIB i dragged a UIScrollView, and a few buttons at the bottom of the page. Then when i build and ran the application, the application scrolls but the button that i added at the extreme bottom of the page can't

  • Prevent a textbox from scrolling when adding text 2009-02-26

    I'm adding new logs line to a WinForms TextBox object, and this causes the textbox to scroll to the bottom. How can I prevent this and retain my current position? (a short code snippet would help) --------------Solutions------------- Actually, Append

  • UIWebView doesn't scroll when embedded in UIScrollView 2009-04-08

    I have an UIScrollView which contains 3 UIWebview. The problem is that my webview no more scroll on touch. Do you have an idea ? Thanks Thierry --------------Solutions------------- UIWebView implements scrolling internally, so its own scrolling confl

  • Is there a way to hide the scroll indicators in an UIScrollView? 2009-05-04

    I've got an use case where those indicators disturb the user interaction. Can I subclass and overide an method or something similar to remove the scoll indicators from the scroll view? --------------Solutions------------- Set the showsHorizontalScrol

  • UIPickerView tap to scroll & custom row UIViews 2010-08-26

    You can scroll an UIPickerView both by swiping and by tapping items under or above the selection belt. You can populate an UIPickerView by either specifying NSString as titles or reusable UIViews for each row. What I've noticed is that when I switche

  • how to scroll images vertically in UIScrollView 2011-02-26

    I am new to iphone programming .i need to add images in scroll view that images should scroll vertically .and suggest me best resource for UIScroll View tutorial --------------Solutions------------- http://developer.apple.com/library/ios/documentatio

  • viewController added to UIScrollView not calling its viewDidAppear method 2011-05-23

    I have a UIScrollView which has 2 different views added via viewController1.view and viewController2.view properties. I want to be notified when viewController1.view or viewController2.view has appeared on screen. Tried to use the viewDidAppear metho

  • ScrollView not scrolling after adding content dynamically 2011-06-24

    Here is my layout : <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <ScrollView android:id="@+id/button_scroll" a

  • Zooming and Scrolling large images in UIScrollView 2011-09-06

    I've been stuck at this for quite some time. I've looked at many other answers and also at Apple's examples. What I want to know is how I can go about loading large images in UIScrollView, and be able to page through them and zoom in to them, like th

  • Why is the tableview being scrolled after adding into a uialertview and seting pagingEnabled as NO? 2011-09-30

    I add a UITableview into a UIAlertview, and set the pagingEnabled as NO, but when I dragged the table, it is still scrolling/paging left or right! Why? I found that in iPhone 3GS, it can not to be scrolled/paged, but in iPhone 4, it can be scrolled/p

  • There is no scroll after adding an Overlay to MapView 2011-11-15

    I'm fighting with following problem now: I add a simple overlay to my mapview. It doesn't draw anything, it is just a help overlay for detecting scroll is ended (see response) Here is the code of it: public class ScrollDetectionOverlay extends Overla

  • UITableView won't scroll when added as a subview 2011-12-19

    I have a UIView called tableContainer, and I am adding a UITableView from the class WidgetTable as a subview of tableContainer, but although it adds successfully, the tableview won't scroll. How can I make it scroll? WidgetTable *widTable = [[WidgetT

  • iOS: UIImageViews added to UIScrollView before ASIHTTP finishes fetching image data 2012-01-08

    I'm new to iOS programming and I'm trying to create a scroll view that shows images in a grid. I use ASIHTTPRequest to fetch images from a web service I created. In -viewDidLoad I call a method to fetch the images and then add image views to the scro

Copyright (C) pcaskme.com, All Rights Reserved.

processed in 0.525 (s). 13 q(s)