Search code examples
ios6

ios : UIScrollView with UITableView


I want to implement one page with vertical scroll view which contains some Images, Labels and one table view in bottom.

Table may have any number of rows. When user scroll to the top other elements such as images, labels should be hide but table should be visible at the top of screen and only table items should be scrolled.

I have tried by setting the currentoffset of scrollview in method scrollViewDidEndDecelerating but its not such smooth.

Scroll view first goes above, comes down and then set the table at top.

Can you please suggest me what should i implement here?

Thanks.


Solution

  • Try this....

    // Add image in scrollView
    serviceImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"row.png"]];
    [serviceImage setBackgroundColor:[UIColor clearColor]];
    serviceImage.frame = CGRectMake(10, 10, 300, 100);
    [myScrollView addSubview:serviceImage];
    [serviceImage release];
    
    // Add label in scrollView
    UILabel *rateLbl = [[UILabel alloc]initWithFrame:CGRectMake(10, 105, 300, 20)];
    rateLbl.text = @"Rates";
    rateLbl.font = [UIFont boldSystemFontOfSize:17.0];
    rateLbl.textColor = [UIColor colorWithRed:244/255.0 green:29/255.0 blue:94/255.0 alpha:1.0];
    rateLbl.textAlignment = UITextAlignmentLeft;
    rateLbl.backgroundColor = [UIColor clearColor];
    [myScrollView addSubview:rateLbl];
    [rateLbl release];
    
    // Add table in scrollView
    int heightRateTbl;
    heightRateTbl = [productType count] * 44;
    rateTableView.frame =CGRectMake(10, expectedLabelSize.height + expectedDecLblSize.height + heightDayTbl + 555, 300, heightRateTbl);  
    rateTableView.scrollEnabled = NO;
    rateTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
    [rateTableView reloadData];
    
    You can enable or disable scroll according your choice.
    
    // Set scrollView height
    myScrollView.contentSize = CGSizeMake(320, 125 + heightRateTbl);
    

    Do not forget to set delegates and declare all things(in .h file and in .xib file).

    Hope i helped.