-3

I have tried this code but scrollview is not working. Please help

  scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
        scrollView.showsVerticalScrollIndicator=YES;
        CGRect contentRect = CGRectZero;
        for (UIView *view in scrollView.subviews) {
            contentRect = CGRectUnion(contentRect, view.frame);
        }
        scrollView.contentSize = contentRect.size;
       //scrollView.contentSize=CGSizeMake(self.view.bounds.size.width,tableView.bounds.size.height+100);
        [self.view addSubview:scrollView];

        UITableView *tableView=[[UiTableView alloc]initWithFrame:CGRectMake(0,200, self.view.bounds.size.width, self.view.bounds.size.height)];
        tableView.dataSource=self;
        tableView.delegate=self;
        //tableView.keepOneSectionOpen = YES;
        //tableView.initialOpenSections = [NSSet setWithObjects:@(0), nil];
        tableView.scrollEnabled = NO;
        tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
        [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:kTableViewCellReuseIdentifier];
        [tableView registerNib:[UINib nibWithNibName:@"AccordionHeaderView" bundle:nil] forHeaderFooterViewReuseIdentifier:kAccordionHeaderViewReuseIdentifier];

        UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width,200)];
        imageView.image=[UIImage imageNamed:@"download (1).jpeg"];
        imageView.userInteractionEnabled=YES;
        imageView.alpha=1;
        [scrollView addSubview:imageView];
        [scrollView addSubview:tableView];
praveen kumar
  • 141
  • 10
  • please make it clear what you want to ask and make your question readable. – Subhash Sharma May 05 '16 at 06:48
  • your question is not clear –  May 05 '16 at 06:56
  • Possible duplicate of [iOS - UIScrollView is not working (it doesn't scroll at all - the image stays fixed)](http://stackoverflow.com/questions/9702471/ios-uiscrollview-is-not-working-it-doesnt-scroll-at-all-the-image-stays-fi) – Rajesh May 05 '16 at 06:56
  • i am implementing Accodion table view in a scroll view. i want scroll view content size to increase when ever the tableview expands i have other objects apart from tableview in ios – praveen kumar May 05 '16 at 07:00

2 Answers2

0

UITableView is a subclass of UIScrollView, not a subview, so you should just use the table view directly. For more information read this explanation

Community
  • 1
  • 1
  • 1/3 rd of my screen has imageview and remaining i have tableView. i kept both in the scroll view. But my tableView is an accordion tableView it expands so does i want my scrollview content size to expanding accordingly – praveen kumar May 05 '16 at 08:32
0

I think the way you did is not correct. If you want to add an image above table view, try using tableHeaderView.

 UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(XXX, YYY, XXX, YYY)];
 self.tableView.tableHeaderView = imageView;
sasi kumar
  • 723
  • 5
  • 14
  • 1/3 rd of my screen has imageview and remaining i have tableView. i kept both in the scroll view. But my tableView is an accordion tableView it expands so does i want my scrollview content size to expanding accordingly – praveen kumar May 05 '16 at 08:29
  • In this case, after reloading or changing the cell height (with or without animation) complete pass the content size of table view plus imageview height to scrollviews content size. – sasi kumar May 05 '16 at 09:48