Question

I am developing an app where i click a button and a bunch of controls (custom view) add at the bottom of the screen. I can click the button as many times as i want. So i end up adding controls at the bottom. I want to scroll up and count how many i added. Suppose i intended to add the custom view 5 times. I added 4.Scroll up count how many i added. I added 4, so scroll down, add 1 more and scroll up and save/do some calculation. But i am unable to scroll up after adding the custom controls. The screen shows the most recently added custom view and stays there. I cannot scroll up to check how many times i have added. What am i doing wrong.?Any ideas? So first time i click to add custom view, this code executes

ITMCustomView *customView = [[ITMCustomView alloc] initWithFrame:
    CGRectMake(187, 560, 400, 400)];
customView.delegate = self;
[self.scrollView addSubview:customView];

The custom view itself has a "Add More" button. If i click that then the above action should perform ,adding the custom control again. So i do this on "Add More"

[self.delegate addNewSize:CGRectMake(187,self.y+ 400 , 400, 400)];

What i am doing is passing the new location where the new custom view has to be created. So that delegate launches this method

- (void)addNewSize:(CGRect)frame
{
    ITMCustomView *cView = [[ITMCustomView alloc] initWithFrame:frame];
    cView.delegate =self;
    CGPoint scrollPoint = CGPointMake(0.0, (frame.origin.y/500)*400);
    [self.scrollView setContentOffset:scrollPoint animated:YES];

    [self.scrollView addSubview:cView];
}

This is actually a continuation of my question Add a bunch of controls dynamically to screen in iOS But i accepted answer (which is true answer for that question) and since its an extension wanted to start a new question. If you need more information please ask.Thanks...

Was it helpful?

Solution

you need to use setContentSize after adding your ITMCustomView. like

[self.scrollView setContentSize:CGSizeMake(320, 800)];

you've to set your scrollView contentSize dyncamically, each time whenever you are adding your custom view.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top