1

I add a custom view to my UIViewController dynamically. It adds perfectly now, no exception.But the screen is stuck. My scrollview is not functional. I got this problem earlier and people suggested use setContentSize. I did that and it worked fine. Now I have a new scenario.I have 2 screens.In screen A i save values .Then i click a bar button item on screen A and go to screen B. Here in screen B (it's a tableviewcontroller) I select one row and go back to screen A and fill the values accordingly (basically load the saved values that I saved in the beginning of the app). I fill them correctly and also add the scroll view but it is stuck.It doesn't move neither up/down. I have this code written for adding the subview and setting the scroll-view size and frame size.

ITMCustomView *cView = [[ITMCustomView alloc] initWithFrame:CGRectMake(187, 660, 400, 400)
                                                         andOrderedItem:@"New"
                                                                 andTag:self.tagNumber
                                                          withFoldArray:self.foldTypeArray
                                                          withRollArray:self.rollTypeArray];

                cView.tag =self.tagNumber;
            NSLog(@"Assigned tag is %d",cView.tag);

            cView.delegate = self;

            CGPoint scrollPoint = CGPointMake(0.0, (cView.frame.origin.y/500)*400);
            [self.scrollView setContentOffset:scrollPoint animated:YES];

            [self.scrollView addSubview:cView];

            CGFloat scrollViewHeight = 0.0f;
            for (UIView *view in self.scrollView.subviews)
            {
                scrollViewHeight += view.frame.size.height;
            }

            CGSize newSize = CGSizeMake(320,scrollViewHeight);

            [self.scrollView setContentSize:newSize];
            NSLog(@"947 the tag number is %d",self.tagNumber);

I check the value of scrollViewHeight..its 3254.000..I changed it to say 4000 as someone suggested increasing height worked. So what am i doing wrong. This question follows another question of mine Navigating back to UIViewController from TableViewController using NSNotifications If you need more info please ask.Thanks.

Community
  • 1
  • 1
RookieAppler
  • 1,517
  • 5
  • 22
  • 58

2 Answers2

1

Got mine working after I used did appear instead of will appear.

- (void) viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    self.scrollView.contentSize = self.viewMain.bounds.size;
}
Mickey
  • 11
  • 1
0

Check the scrollingEnabled property on the scroll view. Unsurprisingly, it needs to be set to YES. If this is the case and it still doesn't work, check if the view (and its superviews) has userInteractionEnabled set to YES as well. In the debugger, you can do po [self.view recursiveDescription] to get the view hierarchy back, that may give you some helpful information as well.

Scott Berrevoets
  • 16,921
  • 6
  • 59
  • 80
  • Thanks. The scrollingEnabled was set YES already. The po [self.view recursiveDescription] showed there were 174 userInteractionEnabled and all 174 were userInteractionEnabled = NO; The custom view I added has some buttons,textfields.All of them are enabled. I can press them,enter values etc.This is the first time i used po anything..so how do i proceed? This is what came up for scroll view | ; layer = ; contentOffset: {0, 0}> – RookieAppler Dec 26 '12 at 22:23
  • Do a `print (BOOL) self.scrollView.userInteractionEnabled`. It needs to be `YES` for your scrollview to work. If it is set to `YES`, I'm not sure what the problem could be, everything else seems to be fine. – Scott Berrevoets Dec 26 '12 at 22:55
  • 2
    @Scott.I got this on further research http://stackoverflow.com/questions/2824435/uiscrollview-not-scrolling I selected scroll view on my story board. Went to File Inspector and unchecked "Use Autolayout" checkbox. Seems to work now. Will test further. – RookieAppler Dec 26 '12 at 22:56