-1

I have used a UIScroll View. It has a contentView (of type UIView) which again has a questionView (UIView) and 2 table views (UITableView). I want questionView and table views to scroll together so I disabled scrolling of table views hoping that scrollView will handle the scrolling. But its not happening. I suspect that the issue is with non-scrollable table views because of which Scroll view is not able to identify the right height of its contentView and hence, not scrolling. For enabling scroll, I added:

self.questionTableView.scrollEnabled = self.answerTableView.scrollEnabled = NO;
self.scrollView.delegate = self;
_scrollView.scrollEnabled = YES;

I read couple of questions on stack overflow but none of them fit my requirement.

enter image description here

A_G
  • 2,260
  • 3
  • 23
  • 56
  • Please tell the reason of down-voting. I will improve on that – A_G Feb 01 '17 at 13:43
  • 1
    your question is too broad. What is the issue ? Is your scrollview not scrolling ? Why do you have a tableView in a scroll View ? The easisest way would be use one tableView and play with the sections. – Teja Nandamuri Feb 01 '17 at 13:51
  • O so i can have a 1 main table view with 2 sections. first section for the question view and the next section to accommodate questionTableView and answerTableView (the last 2 table views are adjacent to each other). – A_G Feb 01 '17 at 13:56
  • yes. You can control every section/row attributes in the tableView! – Teja Nandamuri Feb 01 '17 at 13:57
  • Sounds good. Thanks! – A_G Feb 01 '17 at 13:58

1 Answers1

2

set scroll view content size after table load

float sizeOfContent = 0;
 NSInteger questionTblHight = self.questionTableView.contentSize.height;
 NSInteger answerTbHight = self.answerTableView.contentSize.height;

sizeOfContent = questionTblHight+answerTbHight;

scrollView.contentSize = CGSizeMake(scrollView.frame.size.width, sizeOfContent);
Ron Gahlot
  • 1,396
  • 8
  • 18
  • I tried changing content size according to table's height but didn't work. – A_G Feb 01 '17 at 13:54
  • 1
    make sure some point 1.set content size after table data load 2. Add UIScrollViewDelegate – Ron Gahlot Feb 01 '17 at 14:03
  • Thanks! It works!! As of now I am setting content size after each cellForRowAtIndexPath. Is there any native method to identify if all the cells have reloaded? I dont want to use NSTimer and all. – A_G Feb 01 '17 at 15:02
  • http://stackoverflow.com/questions/4163579/how-to-detect-the-end-of-loading-of-uitableview this link help you – Ron Gahlot Feb 02 '17 at 04:34
  • Thanks for the link. The cells which are visible in the first screen are tappable but after scrolling down, even though i can see the cells but they are not tappable. I tried _scrollView.delaysContentTouches = YES; as well but no luck – A_G Feb 02 '17 at 05:36
  • i think you should to use _scrollView.userInteractionEnabled = YES; – Ron Gahlot Feb 02 '17 at 12:25