I have a method “someMethod” declared in OneViewController.h
@interface OneViewController
{
UIView *tempView;
..
}
-(void) someMethod ;
@end
and implemented in OneViewController.m file
@implementation OneViewController
-(void) someMethod
{
tempView = [[UIView alloc]initWithFrame:CGRectMake(100, 50, 200, 250)];
tempView.backgroundColor = [UIColor yellowColor];
if([[self.view subviews] containsObject:tempView])
[tempView removeFromSuperView];
else
[self.view addsubview:tempView];
}
I want to call someMethod when present at different viewController – secondViewController
(something like [OneViewController someMethod]), So that when I get back to OneViewController I can see the changes made by someMethod.
Do I need to use appDelegate methods?
I have tried following but it doesn’t work.
neViewController *newViewController = [[OneViewController alloc] init];
[newViewController someMethod];
Thanks for any help in advance..
In the SecondViewController, declare a reference for OneViewController class. You can have assign property. Set the reference before you move to SecondViewController. Now with the reference, you can call the instance method
[_oneView someMethod].Edit:
Declare
Also add the assign property,
Synthesize the variable in .m file.
While showing the SecondViewController from OneViewController, just add the following line.