Trying to put 'forIndex

NSInteger)index' in method title passing message of current page to make app remember stay on the same page when changing orientation (at the moment it goes back to page1):
Code:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ NSLog(@"willAnimateRotationToInterfaceOrientation");
UIInterfaceOrientation o = self.interfaceOrientation;
if ((o == UIInterfaceOrientationPortrait) || (o == UIInterfaceOrientationPortraitUpsideDown)) {D = 1;[pagingScrollView removeFromSuperview];[self setPaging];}
if ((o == UIInterfaceOrientationLandscapeLeft) || (o == UIInterfaceOrientationLandscapeRight)) {D = 2;[pagingScrollView removeFromSuperview];[self setPaging];}}
- (void)viewDidLoad {
D = 1;
[self setPaging];}
- (void)setPaging {
recycledPages = [[NSMutableSet alloc] init];
visiblePages = [[NSMutableSet alloc] init];
CGRect F;
F = [self frameForPagingScrollView];
pagingScrollView = [[UIScrollView alloc] initWithFrame:F];
if (D == 1) {
pagingScrollView.pagingEnabled = YES;
pagingScrollView.backgroundColor = [UIColor whiteColor];
pagingScrollView.showsVerticalScrollIndicator = NO;
pagingScrollView.showsHorizontalScrollIndicator = NO;
pagingScrollView.contentSize = CGSizeMake(320.0f * [self pdfPageCount], 435.0f);
pagingScrollView.delegate = self;
pagingScrollView.clipsToBounds = YES;
pagingScrollView.bounces = YES;
[self.view addSubview:pagingScrollView];
[self tilePages];
[self.isvL removeFromSuperview];
[pagingScrollView addSubview:self.isvP];}
else if (D == 2) {
pagingScrollView.pagingEnabled = YES;
pagingScrollView.backgroundColor = [UIColor whiteColor];
pagingScrollView.showsVerticalScrollIndicator = NO;
pagingScrollView.showsHorizontalScrollIndicator = NO;
pagingScrollView.contentSize = CGSizeMake(480.0f * [self pdfPageCount], 300.0f);
pagingScrollView.delegate = self;
pagingScrollView.clipsToBounds = YES;
pagingScrollView.bounces = YES;
[self.view addSubview:pagingScrollView];
[self tilePages];
[self.isvP removeFromSuperview];
[pagingScrollView addSubview:self.isvL];}}
- (CGRect)frameForPagingScrollView {
CGRect frame;
if (D == 1) {
frame = CGRectMake(0.0f, 0.0f, 320.0f, 435.0f);
frame.size.width += (0);}
else if (D == 2) {
frame = CGRectMake(0.0f, 0.0f, 480.0f, 300.0f);
frame.size.width += (0);}
return frame;}
- (void)tilePages {
if (D == 1) {
CGRect visibleBounds = pagingScrollView.bounds;
int firstNeededPageIndex = floorf(CGRectGetMinX(visibleBounds) / CGRectGetWidth(visibleBounds));
int lastNeededPageIndex = floorf((CGRectGetMaxX(visibleBounds)-1) / CGRectGetWidth(visibleBounds));
firstNeededPageIndex = MAX(firstNeededPageIndex, 0);
lastNeededPageIndex = MIN(lastNeededPageIndex, [self pdfPageCount] - 1);
for (ISVportrate *page in visiblePages) {
if (page.index < firstNeededPageIndex || page.index > lastNeededPageIndex) {
[recycledPages addObject:page];
[page removeFromSuperview];}}
[visiblePages minusSet:recycledPages];
for (int index = firstNeededPageIndex; index <= lastNeededPageIndex; index++) {
if (![self isDisplayingPageForIndex:index]) {
ISVportrate *page = [self dequeueRecycledPageP];
if (page == nil) {
page = [[[ISVportrate alloc] init] autorelease];}
[self configurePageP:page forIndex:index];
[pagingScrollView addSubview:page];
[visiblePages addObject:page];}}}
else if (D == 2) {
CGRect visibleBounds = pagingScrollView.bounds;
int firstNeededPageIndex = floorf(CGRectGetMinX(visibleBounds) / CGRectGetWidth(visibleBounds));
int lastNeededPageIndex = floorf((CGRectGetMaxX(visibleBounds)-1) / CGRectGetWidth(visibleBounds));
firstNeededPageIndex = MAX(firstNeededPageIndex, 0);
lastNeededPageIndex = MIN(lastNeededPageIndex, [self pdfPageCount] - 1);
for (ISVLandscape *page in visiblePages) {
if (page.index < firstNeededPageIndex || page.index > lastNeededPageIndex) {
[recycledPages addObject:page];
[page removeFromSuperview];}}
[visiblePages minusSet:recycledPages];
for (int index = firstNeededPageIndex; index <= lastNeededPageIndex; index++) {
if (![self isDisplayingPageForIndex:index]) {
ISVLandscape *page = [self dequeueRecycledPageL];
if (page == nil) {
page = [[[ISVLandscape alloc] init] autorelease];}
[self configurePageL:page forIndex:index];
[pagingScrollView addSubview:page];
[visiblePages addObject:page];}}}}
changes (below) make it remember which page its on but only because paging scrollview not deleted, pagingScrollView frame still set at portrait with landscape setting (heigh-wise wont let vertical scroll unless zoomedin).
when I change '- (void)willAnimateRotationToInterfaceOrientation' pagingScrollView isn't deleted.
Code:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation forIndex:(NSUInteger)index{ NSLog(@"willAnimateRotationToInterfaceOrientation");
UIInterfaceOrientation o = self.interfaceOrientation;
if ((o == UIInterfaceOrientationPortrait) || (o == UIInterfaceOrientationPortraitUpsideDown)) {D = 1;[pagingScrollView removeFromSuperview];[self setPaging:index];}
if ((o == UIInterfaceOrientationLandscapeLeft) || (o == UIInterfaceOrientationLandscapeRight)) {D = 2;[pagingScrollView removeFromSuperview];[self setPaging:index];}}
- (void)viewDidLoad {
D = 1;
int index;[self setPaging:index];}
- (void)setPaging:(NSUInteger)index {
recycledPages = [[NSMutableSet alloc] init];
visiblePages = [[NSMutableSet alloc] init];
CGRect F;
F = [self frameForPagingScrollView];
pagingScrollView = [[UIScrollView alloc] initWithFrame:F];
if (D == 1) {
pagingScrollView.pagingEnabled = YES;
pagingScrollView.backgroundColor = [UIColor whiteColor];
pagingScrollView.showsVerticalScrollIndicator = NO;
pagingScrollView.showsHorizontalScrollIndicator = NO;
pagingScrollView.contentSize = CGSizeMake(320.0f * [self pdfPageCount], 435.0f);
pagingScrollView.delegate = self;
pagingScrollView.clipsToBounds = YES;
pagingScrollView.bounces = YES;
[self.view addSubview:pagingScrollView];
[self.isvL removeFromSuperview];
[pagingScrollView addSubview:self.isvP];
for (ISVportrate *page in visiblePages) {
int index;
if (page.index == index) {
ISVportrate *page = [self dequeueRecycledPageP];
if (page == nil) {
page = [[[ISVportrate alloc] init] autorelease];}
[self configurePageP:page forIndex:index];
[pagingScrollView addSubview:page];
[visiblePages addObject:page];}}}
else if (D == 2) {
pagingScrollView.pagingEnabled = YES;
pagingScrollView.backgroundColor = [UIColor whiteColor];
pagingScrollView.showsVerticalScrollIndicator = NO;
pagingScrollView.showsHorizontalScrollIndicator = NO;
pagingScrollView.contentSize = CGSizeMake(480.0f * [self pdfPageCount], 300.0f);
pagingScrollView.delegate = self;
pagingScrollView.clipsToBounds = YES;
pagingScrollView.bounces = YES;
[self.view addSubview:pagingScrollView];
for (ISVLandscape *page in visiblePages) {
int index;
if (page.index == index) {
ISVLandscape *page = [self dequeueRecycledPageL];
if (page == nil) {
page = [[[ISVLandscape alloc] init] autorelease];}
[self configurePageL:page forIndex:index];
[pagingScrollView addSubview:page];
[visiblePages addObject:page];}}
[self.isvP removeFromSuperview];
[pagingScrollView addSubview:self.isvL];}}
//- (CGRect)frameForPagingScrollView { same as above
//- (void)tilePages {same as above
Any ideas? Thanks