I have a viewcontroller, if I press a button, another viewController is loaded, but the first is not unloaded. I want to access a variable form the first view controller from the second, actually a UIScrollView, so that I can use it in this way:
scroll1.hidden = YES;
How can I do this? I tried importing the .h file, but still I cannot use the UIScrollView
EDIT:
NSArray* stack = [self.navigationController viewControllers];
NSInteger currentIndex = [stack indexOfObject:self];
ViewController* linkToA = (ViewController*)[stack objectAtIndex:currentIndex - 1];
[linkToA.scroll1.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
[linkToA.scroll1 addSubview:linkToA.backgroundImage];
or
ViewController *linkToA = [[ViewController alloc] init];
linkToA = (ViewController*)self.presentingViewController;
[linkToA.scroll1.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
[linkToA.scroll1 addSubview:linkToA.backgroundImage];
just make sure first view controller does have a property of your scrollView in the header:
if you don’t have a latest xcode put
@synthesize scrollViewto the implementation of the first controllerlets say your first controller is A and the second is B
if B is a added as a modal then use this:
if B is added to navigationControllerStack:
after you have a linkToA you have to do
hope this will help