0

I have a detailviewcontroller, Dance, with a scrollview. I have set the size of the detailViewController and implemented the scrollview with,

- (void)viewDidAppear:(BOOL)animated
{
self.title = self.full_name;
[super viewDidAppear:animated];
pagescroll.ScrollEnabled = YES;
[pagescroll setContentOffset:CGPointMake(0,0) animated:NO];
pagescroll.contentSize = CGSizeMake(320, 1300);
}

The detailviewcontroller has 'subpages' (more details about the object) to which it is connected. It handles the connections to the pages with prepareforsegue. I can pass information to the subpages without any problem.

Upon re-entering the detailviewcontroller from one of the subpages, the scrollview will not scroll all the way to the top, i.e. the detailviewcontroller page is truncated. The page is also truncated differently depending on how far down I had scrolled before I clicked a button to go to one of the subpages.

Help me eliminate the scourge of truncation.

andrew lattis
  • 1,549
  • 13
  • 16

1 Answers1

0

The viewDidAppear method will always be called when after the view is displayed, so you might want to see which line of codes you think do not belong there, such as initialisation codes.

My assumptions are these line of codes that can be put inside viewDidLoad, since viewDidLoad is only called once when the view is loaded into memory. I think you do not always enable scroll and set content size of the scroll view every time you re-enter the detail view controller:

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = self.full_name;
    pagescroll.ScrollEnabled = YES;
    pagescroll.contentSize = CGSizeMake(320, 1300);
}

And then you are only left with setting the content offset in viewDidAppear to avoid the truncation:

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [pagescroll setContentOffset:CGPointMake(0,0) animated:NO];
}

Or maybe you can just reset the content offset right before the view will disappear:

- (void)viewWillDisappear:(BOOL)animated
{
    pagescroll.contentOffset = CGPointMake(0, 0);
    [super viewWillDisappear:animated];
}
Valent Richie
  • 5,226
  • 1
  • 20
  • 21
  • Added: [self.pagescroll setContentOffset:CGPointMake(0,0) animated:YES]; to the viewWillDisappear method. It looks kind of funny when the subpage is loaded, but it works. – Andrew Hart May 21 '13 at 00:09
  • I guess what was happening is that the point (0,0) was set to the top of wherever in the scrollview I was when I went to the subpage(?). – Andrew Hart May 21 '13 at 00:14
  • contentOffset is how far the view has moved in the scroll view, so setting it to (0,0) is like scrolling to the top left again: http://stackoverflow.com/questions/3339798/what-does-contentoffset-do-in-a-uiscrollview – Valent Richie May 21 '13 at 00:28