UIScrollView untouchable as subclass, fine normally

Discussion in 'iOS Programming' started by carlosbutler, Apr 28, 2011.

  1. carlosbutler, Apr 28, 2011
    Last edited: Apr 28, 2011

    carlosbutler macrumors 6502a


    Feb 24, 2008
    London City
    I had a working scrollview, but decided to create it from a subclass to make my code look tidy. It worked fine before, it could scroll and the UIButtons in it worked fine.

    Loading it as a subclass, it loads and displays correctly but it will not scroll any more nor will the buttons touch. I guess something is in front of it, blocking any touch but, from what I have written, there is nothing in front and it should work fine.

    I am on the move now, and can post some code if anyone would like to see. But I'm sure I am just missing some line of code? As I said the scroll view was working perfectly fine before hand, so there is nothing missing from that.


    EDIT: Code below
    #import <UIKit/UIKit.h>
    #import "MyScrollView.h"
    @interface AppgViewController : UIViewController <NSXMLParserDelegate, UIScrollViewDelegate> {
    	// Parsing the XML
    	NSXMLParser *xmlParser;
    	// Tab bar icons
    	UIButton *button_TabBarOne, *button_TabBarTwo, *button_TabBarThree, *button_TabBarFour;
    	UIImageView *imageview_TabBarOne, *imageview_TabBarTwo, *imageview_TabBarThree, *imageview_TabBarFour;
    	MyScrollView *myScrollView;
    @property (nonatomic, retain) UIButton *button_TabBarOne, *button_TabBarTwo, *button_TabBarThree, *button_TabBarFour;
    @property (nonatomic, retain) UIImageView *imageview_TabBarOne, *imageview_TabBarTwo, *imageview_TabBarThree, *imageview_TabBarFour;
    @property (nonatomic, retain) MyScrollView *myScrollView;
    - (void)hello;
    - (void)fadeOut;
    - (void)addTabBar;
    - (void)loadRScrollView;
    - (void)parseXML;
    #import "AppViewController.h"
    @implementation AppViewController
    @synthesize button_TabBarOne, button_TabBarTwo, button_TabBarThree, button_TabBarFour;
    @synthesize imageview_TabBarOne, imageview_TabBarTwo, imageview_TabBarThree, imageview_TabBarFour;
    @synthesize myScrollView;
    // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
    - (void)viewDidLoad {
    	[self addTabBar];
    	[self parseXML];
    	[self fadeOut];
            [self loadScrollView];
    	[super viewDidLoad];
    - (void)loadScrollView {	
    	myScrollView = [[MyScrollView alloc] init];
    	[self.view addSubview:myScrollView];
    	[self.view bringSubviewToFront:myScrollView];
    	myScrollView.userInteractionEnabled = YES;
    #import <UIKit/UIKit.h>
    @interface MyScrollView : UIView <UIScrollViewDelegate> {  
    - (void)hello;
    #import "MyScrollView.h"
    @implementation MyScrollView
    - (id)initWithFrame:(CGRect)frame
        self = [super initWithFrame:frame];
        if (self) {
            // Initialization code
    	UIScrollView *scrollview_One = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 205, 500)];
    	scrollview_One.showsHorizontalScrollIndicator = scrollview_One.showsVerticalScrollIndicator = NO;
    	scrollview_One.contentSize = CGSizeMake(205, 685);
    	scrollview_One.backgroundColor = [UIColor grayColor];
    	scrollview_One.delegate = self;
    	UIButton *button_One = [UIButton buttonWithType:UIButtonTypeCustom];
    	button_One.frame = CGRectMake(0, 0, 205, 137);
    	[button_One setImage:[UIImage imageNamed:@"thumb_010.jpg"] forState:UIControlStateNormal];
    	button_One.userInteractionEnabled = YES;
    	UIButton *button_Two = [UIButton buttonWithType:UIButtonTypeCustom];
    	button_Two.frame = CGRectMake(0, 200, 205, 137);
    	[button_Two setImage:[UIImage imageNamed:@"thumb_011.jpg"] forState:UIControlStateNormal];
    	UIButton *button_Three = [UIButton buttonWithType:UIButtonTypeCustom];
    	button_Three.frame = CGRectMake(0, 400, 205, 137);
    	[button_Three setImage:[UIImage imageNamed:@"thumb_012.jpg"] forState:UIControlStateNormal];
    	UIButton *button_Four = [UIButton buttonWithType:UIButtonTypeCustom];
    	button_Four.frame = CGRectMake(0, 600, 205, 137);
    	[button_Four setImage:[UIImage imageNamed:@"thumb_013.jpg"] forState:UIControlStateNormal];
    	UIButton *button_Five = [UIButton buttonWithType:UIButtonTypeCustom];
    	button_Five.frame = CGRectMake(0, 800, 205, 137);
    	[button_Five setImage:[UIImage imageNamed:@"thumb_014.jpg"] forState:UIControlStateNormal];
    	[scrollview_One addSubview:button_One];
    	[scrollview_One addSubview:button_Two];
    	[scrollview_One addSubview:button_Three];
    	[scrollview_One addSubview:button_Four];
    	[scrollview_One addSubview:button_Five];
    	[self addSubview:scrollview_One];
    	[self bringSubviewToFront:scrollview_One];
    	return self;
  2. Sydde macrumors 68020


    Aug 17, 2009
    This does not make sense. If you want the buttons to slide around with the scroll view, you make them subviews of the content view. If you want them to be fixed in place above the scroll view, you make the subviews of the superview (MyScrollView). Generally speaking, you do not add subviews to a scroll view. Its subviews are the content view and the clip view. Anything more and it gets confused.

    I assume you have not written and delegate methods because you have not gotten around to it?

Share This Page