49827

Why the UIScrollViewDelegate is not working?

Question:

I have a viewController called "HaveScrollController", and this is something like this:

@interface HaveScrollController : UIViewController <UIScrollViewDelegate>{ IBOutlet UIScrollView *scrollView; IBOutlet UIView *firstView; IBOutlet UIView *secondView; IBOutlet UIView *thridView; IBOutlet UIView *fourthView; } @property (retain, nonatomic) UIScrollView *scrollView; @property (retain, nonatomic) UIView *firstView; @property (retain, nonatomic) UIView *secondView; @property (retain, nonatomic) UIView *thridView; @property (retain, nonatomic) UIView *fourthView; @end

and the .m is something like this:

@synthesize scrollView,firstView,secondView,thridView,fourthView; - (void)viewDidLoad { [super viewDidLoad]; [self.view addSubview:scrollView]; scrollView.delegate = self; } - (void)scrollViewDidScroll:(UIScrollView *)scrollView{ NSLog(@"scroll detected"); } @end

I make all the connection to the IB already. And I wanna to use this controller in my "TestAppController", which is something like this, it don't use IB, and generate the interface using code:

@interface TestAppController : UIViewController <UIScrollViewDelegate,UIActionSheetDelegate, UITextFieldDelegate> { HaveScrollController *scollViewController; }

The .m is something like this in the loadView method:

scollViewController = [[HaveScrollController alloc] initWithNibName:@"HaveScrollView" bundle:nil]; [mainCanvas addSubview: buttomScollViewController.view]; self.view = mainCanvas; [mainCanvas release];

When I try to scroll the view, but the "scroll detected" is not shown. What did I do wrong? thank you.

Answer1:

Is scrollView scrolling at all? It looks like you forgot to set the contentSize:

scrollView.contentSize = CGSizeMake(320, 400);

Obviously, make sure the contentSize is larger than scrollView's frame so that the scrolling action kicks in.

Recommend

  • _iVar vs. iVar_ for variable naming [closed]
  • How do I know if text exceeds the bounds of a text view?
  • Adding child progress for multiple file download
  • playing video in iOS 5
  • Rails has_many :through association: save instance into join table
  • UIBarButtonItem - Argument of '#selector' cannot refer to local function - Swift 3
  • updatesearchresultsforsearchcontroller not called
  • How can I figure out what UITableViewCell I'm clicking on during a search?
  • Encoding issue with ASIHttpRequest
  • windowScriptObject method not found on Objective-C code
  • Printing input from TextField to a Label in Xcode with Swift
  • Change color of row programmatically in WatchKit
  • Why won't my UITableViewCell deselect and update its text?
  • Objective-C – access extern const with a string containing its name? [duplicate]
  • Unload image of UIImageView thats offscreen
  • CFNetwork SSLHandshake failed (-9806) & (-9800) & (-9830)
  • wrong item changes in recyclerview
  • How to expand parent div to account for child's overflow?
  • Single virtual attribute definition for multiple fields
  • iOS - MKOverlayView custom view rect fills works, but line draws do not
  • Using extern @class in order to add a category?
  • Specifying virtual keyboard type for EditText in XML
  • unrecognized selector with category NSMutableData
  • C# List of Panels
  • Creating PDF from TIFF image using iText
  • Creating Java object from class name with constructor, which contains parameters [duplicate]
  • how to avoid repetitive constructor in children
  • how to save the state in userdefaults of accessory checkmark-iphone
  • Saving Changes After In-App Purchase Has Been Purchased
  • QLPreviewController hide print button in ios6
  • Database structure design with variable amounts of fields
  • Deleting and Updating values from a cusrsor adapter
  • How do I fake an specific browser client when using Java's Net library?
  • Align navbar back button on right side
  • How to get a value (ex: baseURL) in every Karate feature?
  • Possible to stop flickering java tooltip in heavyweight mode?
  • EntityFramework adding new object to nested object collection
  • Checking variable from a different class in C#
  • failed to connect to specific WiFi in android programmatically
  • How can I use threading to 'tick' a timer to be accessed by other threads?