Q:

Make Uiscrollview to move to selected region

Hi I've struck with simple problem that I've added a uiscollview to view and added buttons to it dynamically from an array and I'm removing them from superview and again adding them to view before loding as in code
- (void)loadGroups {

    if(scroll!=nil){
        if([scroll isDescendantOfView:self.view]){

            [scroll removeFromSuperview];

        }
    }
     NSUInteger n=[self.resultSet.dataObjectList count];
    scroll = [[UIScrollView alloc]init];
    scroll.delegate=self;
    scroll.frame = CGRectMake(0, 0, 320, (height+25));
    [scroll setContentSize:CGSizeMake((width-30)*n, height+25)];
    [scroll setContentOffset:CGPointMake(0, 0) animated:NO];
    scroll.backgroundColor=[UIColor clearColor];
    //scroll.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"GP-BG.png"]];
    [scroll setCanCancelContentTouches:NO];
    scroll.indicatorStyle=UIScrollViewIndicatorStyleWhite;
    scroll.bounces=NO;
    scroll.scrollEnabled=YES;
    scroll.pagingEnabled=NO;
    scroll.showsHorizontalScrollIndicator=NO;
    for(int i=0;i<n;i++)
    {
        MODELRoom *room = [self.resultSet.dataObjectList objectAtIndex:i];
        CGRect rectForTitleButton = CGRectMake(i*(width-30), 0, width-30, height+25);
        int buttonTag =10000+i;
        UIButton *titleButton = [self getButton:room tag:buttonTag ];
        titleButton.tag=buttonTag;
        [titleButton setFrame:rectForTitleButton];
        titleButton.backgroundColor=[UIColor clearColor];
        [scroll addSubview:titleButton];

        CGRect rectForLabel = CGRectMake(i*(width-30), padding-5, width-35, height-20);
        UILabel *label = [[UILabel alloc]init ];
        label.frame=rectForLabel;
        MODELRoom *room1 = [self.resultSet.dataObjectList objectAtIndex:i];
        label.text=(room1).name;
        label.textColor=[UIColor whiteColor];
        label.textAlignment=NSTextAlignmentCenter;
        label.backgroundColor=[UIColor clearColor];
        label.font = [UIFont fontWithName:@"Helvetica" size:14];
        [scroll addSubview:label];

        CGRect rectForImageView = CGRectMake(27.5+(width-30)*i, padding+25, width-90, height-20);
        UIImageView *imageView = [[UIImageView alloc]init ];
        imageView.frame=rectForImageView;
        imageView.backgroundColor=[UIColor clearColor];
        imageView.image=[UIImage imageNamed:@"Group-icon.png"];
        [scroll addSubview:imageView];

    }
    [self.view addSubview:scroll];

    }

my problem is when I select a button after scrolling it is retunig to first button but I need to be there where I've selected the button. please help me where i'm doing wrong...
thanks in advance....  

A:

Try to use this one i hope this will work fine...
[scroll setContentOffset:CGPointMake(titleButton.frame.origin.x, titleButton.frame.origin.y) animated:YES];

