TechChain
TechChain

Reputation: 8944

ios:How to persist object value in viewcontroller

I am having one view controller WebViewController and second is Settings. On tap of button i am adding Settings view controller as subview of webviewcontroller.

menusettings=[self.storyboard instantiateViewControllerWithIdentifier:@"SET"];
[menusettings.view setFrame:CGRectMake(0, 0, 700,600)];
[self.view addSubview:menusettings.view];

I have Webview Object in the Webview controller

@property (strong, nonatomic) IBOutlet UIWebView *wrae_one;

and i am loading data in webview but when i cal function from Settings controller then the value self.wrae_one becoming null. Means when i add setting view controller as subview in webview controller then obejet of webview become null. Is there any way to main it value. In settings i am using this code for calling the function

self.home_webview=[[PRGVwebViewController alloc]init];
[self.home_webview loadWebviewController]

Upvotes: 0

Views: 199

Answers (1)

Luca D'Alberti
Luca D'Alberti

Reputation: 4849

I think that PRGVwebViewController is the class from which the settingsviewcontroller is instantiated. So why do you re alloc the class? Doing this you are creating a new controller, but when you dismiss the settingsviewcontroller, you are seeing the first one. You have to create a reference to the previous controller.

Maybe, the best way is to instantiate the WebViewController as a sharedIstance (singleton), so you can access to it (and only it) wherever you want.

This can be helpful: http://www.daveoncode.com/2011/12/19/fundamental-ios-design-patterns-sharedinstance-singleton-objective-c/

Upvotes: 1

Related Questions