views:

391

answers:

2

I have a scroll view that doesn't scroll right, I've simplified the code for below. It draws the view and some horizontal buttons that i add more stuff to in the real code. If you drag the whitespace between the buttons the view scrolls. If you happen to put your finger on a button, it won't scroll. After a related suggestion, I tried to add the delaysContentTouches = YES line, but it doesn't seem to make a difference. http://stackoverflow.com/questions/650437/iphone-uiscrollview-with-uibuttons-how-to-recreate-springboard

What am I doing wrong? TIA, Rob

Updated the code

- (void)viewDidLoad {
    l = [self landscapeView];
    [self.view addSubview:l];
    [l release];    
}

- (UIScrollView *) landscapeView {
    // LANDSCAPE VIEW
    UIScrollView *landscapeView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 325)];
    landscapeView.backgroundColor = [UIColor whiteColor];
    landscapeView.delaysContentTouches = YES;
    NSInteger iMargin, runningY, n;
    iMargin = 3;
    runningY = iMargin;

    for (n = 1; n <= 38; n++) {
        //add day labels
        UIButton *templabel = [[UIButton alloc] initWithFrame:CGRectMake(iMargin,runningY,320 - ( 2 * iMargin),20)];
        templabel.backgroundColor = [UIColor grayColor];
        [landscapeView addSubview:templabel];
        [templabel release];
        runningY = runningY + 30;
    }
    landscapeView.contentSize = CGSizeMake( 320, runningY);

    return landscapeView; 
}
A: 

I can't duplicate your results; when I create a scrollView and add buttons, scrolling is still active even when doing a touch-down on the button. Are you setting any other UIScrollView properties, or subclassing any methods, that aren't showing up in your simplified code?

Greg Plesur
Don't think so, I updated the code.
dny238
A: 

It looks like one thing that's going on is that the getter for landScapeView is a complicated constructor...so every time you do [self landscapeView] or self.landscapeView, you're creating a whole new UIScrollView and operating on that.

I'd try something like this in your .h file:

@interface MyClass: MyParent {
  UIScrollView *landscapeView;
}

@property (retain) UIScrollView *landscapeView;

...and this in your .m file:

@implementation MyClass

@synthesize landscapeView;

(void)viewDidLoad 
{ l = [[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 325)] autorelease];
  [self.view addSubview:self.landscapeView]; [l release]; 
  landscapeView.backgroundColor = [UIColor whiteColor];
  landscapeView.delaysContentTouches = YES;
   NSInteger iMargin, runningY, n;
  iMargin = 3;
  runningY = iMargin;
  for (n = 1; n <= 38; n++) { //add day labels 
       UIButton *templabel = [[UIButton alloc] initWithFrame:CGRectMake(iMargin,runningY,320 - ( 2 * iMargin),20)];
       templabel.backgroundColor = [UIColor grayColor]; 
       [landscapeView addSubview:templabel]; 
       [templabel release]; runningY = runningY + 30; 
  } 
  landscapeView.contentSize = CGSizeMake( 320, runningY);

}

Greg Plesur
Thanks Greg, I'll try that. I agree it's poorly constructed, old code I think. Do you think that this will fix the scrolling problem?Rob
dny238
Ok, made the change. Still have the issue with the buttons not being clickable. Should i try to make a mini app of the problem and upload it? I'm at a loss.
dny238