Data Retention on VIewController/Views - iphone

Had a quick question:
I have 2 view controllers, and their associated views.
The first VC have images which have been coloured through masking. This is a link to the technique I will be employing.
The second VC and view is simply a settings screen that will hold random content.
Assume this scenario:
First VC with images is loaded up and the coloring is completed
NOTE: Coloring is random and the value is not stored anywhere. With
so many images it would be difficult to store all those random
colors in variables.
On the First VC the user presses the button navigating to the
setting screen
the Second VC is now loaded, via a Modal operation
On the Second VC the user presses a "back" button to return to
the previous VC, which in this case is the First VC.
The question: During navigation and after the the navigation back to the First VC will the images and colors I randomly and programmatically chose still be visible or will I lose those randomly generated colors? If not how do I ensure that what has been rendered on the First VC will be maintained throughout any navigation operations?

As long as the View Controller stays on the navigation stack, all of the data it holds will still be valid when you return to it. Pushing any number of View Controllers on top of the stack will do nothing to the first view controller, but as soon as you pop the first one off of the stack, it will lose any data it had unless saved otherwise and reloaded(in a variable in the App Delegate, for example).

You will not loose the images you created unless you release the first view. Since you are showing the second view on top of first view, all the images will be there. You dont have to worry about saving the colors or images. You can push any number of view controllers on top of this first view controller.
Note that this is valid only if you are not removing/popping/dismissing the first view controller or its view.

Related

How To Always Hide UISplitViewController Details View Controller

Is there anyway to hide the details view controller of a UISplitviewController in all circumstances? I have this requirement where the details VC needs to be hidden (or absent) at first and then slide in from the right when an initial selection is made. This needs to be the case even when a large iPad is in full screen mode.
I know I can simply create my own version of this using a view controller with two child view controllers embed and manipulating constraints, however then I lose the push and pop functionally that you automatically get when in a compact size class.

view controllers using storyboard

i am trying to switch between two view controllers using storyboard. I create a modal seague by control-dragging (on buttons) from 1st view controller to 2nd, and then from the 2nd to the first.
So whenever I click on a button in 1st VC, it takes me to the 2nd VC. This time when i click the button on second VC, does it take me back to the original instance of the 1st VC or it creates a new instance?
If it takes me to the same instance, and user had written some data in some textfields, is there anyway to retain that on screen? (I might want to save them in some variables, and since the program will return back to the same instancem i'll be able to get the variables back)
If it doesn't take me to the same instance, is there any method to do so?
I tried making an instance of 2nd VC and using self.navigarionController push...(instance) but this doesn't swtich the controller.
If i do this pushing using the storyboard, and i do pop in my 2nd VC, it doesn't get popped either.
(and i would also couldn't understand the difference between push,modal and custom seagues)
Create the modal segue from VC1's button to VC2, but not the reverse one. When the VC2's button is tapped, call dismissViewControllerAnimated:completion: to return to where you were.
If you used a push segue instead, you would call popViewControllerAnimated: to go back but that only works if you have your view controllers managed by a UINavigationController.
You can think of push as a way of stepping through a sequence of related scenes while modal is something that's a bit out of the normal flow of the application. (That's not a firm rule but it's a starting point for deciding which way to go.) For 'custom', you write the segue code, so you decide what happens.

Prevent Object Release in Storyboard

I'm looking after a solution to prevent object release in storyboard views.
Here is the deal, I have a storyboard view which contains data grabbed from JSON. This view has relation with another view (First View:List of items -- Second View:Item Details). Now when I tap on an item in first view, it goes to another view and shows the detail (using segue). BUT when I go back to the first view, it needs to grab the data from JSON again. (makes the user angry)
I'm aware of using Tab template, but I can't due to the application user requirements.
I'll be so much appreciated if anybody could help me.
Gratitude.
You are incorrectly implementing the Model-View-Controller pattern. Views should never fetch or hold data. They simply display it. View Controllers also do not hold data. Views and view controllers can be thrown away any time they're not on screen. This is by design.
Create a model class that is responsible for talking to the server and holding the resulting data. The controller should hand the model to the view, and the view should just display what it finds in the model.
I think you need to do a modal Segue from your First View to the Second View. Then when you are finished with the Second View execute [self dismissModalViewControllerAnimated:YES]; in the Second View to dismiss the Second View and return to the First View. This should then display the First View once more with the data.

How to create two sub screens such that one one view changes when the user clicks the button

I am struck with this thing.. Dont know how to implement this one...
My requirement is When..user clicks on the second half of the screen.., Only the second half of the screen should change, So.., modalViewController and pushViewController wont help I guess..,
The first half of the screens remains fixed. Depending on the control logic, I can then navigate to the next respective second half screen and the first part of the screen remains fixed
Add two subview to your view and listen for touches (touchesBegan:withEvent:) on them in your view controller.
Create your own split view controller which mimics a navigation controller but manages its own views. Have a sub view for the bottom part and animate changes / navigation from this controller.

iphone UINavigation Controller

I'm trying to get a better understanding of the UINavigationController. I have 3 .xibs. From .xib1 I am pushing to .xib2. I have to pass data to .xib2 from .xib1.
Controller1 *selectcity = [[Controller1 alloc]initWithNibName:#"Controller1" bundle:nil];
selectcity.item1 = #"hi";
// Push the next view onto our stack
[self.navigationController pushViewController:selectcity animated:YES];
[selectcity release];
I need to pass some data to .xib2 every time it opens that view. Pushing a new view onto the stack every time the user selects a row in the table, and then pressing back, selecting a row, back, selecting a row, back is creating a memoryWarning very quickly and killing the app.
If I add the view as a property and check if it already exists,
if (xib2 == nil) {
}
the viewDidLoad method only gets called the first time the view is called so I can't pass my data to the form.
I can't use viewDidAppear etc. because I don't want to the data to load when coming back from .xib3.
What is the correct way to control memory in this situation? Should I be popping xib2 from the stack every time they press the back button? Is so, what method would I do this?
Thanks for any help!
I'm trying to get a better
understanding of the
UINavigationController. I have 3
.xibs. From .xib1 I am pushing to
.xib2. I have to pass data to .xib2
from .xib1.
First off, you don't pass data between .xibs, you pass data between view controllers.
I need to pass some data to .xib2
every time it opens that view. Pushing
a new view onto the stack every time
the user selects a row in the table,
and then pressing back, selecting a
row, back, selecting a row, back is
creating a memoryWarning very quickly
and killing the app.
Please post more of the code related to this problem. Assuming you're talking about UITableView rows, your app shouldn't have any problems pushing/popping views onto the navigation stack in response to taps on rows.
the viewDidLoad method only gets
called the first time the view is
called so I can't pass my data to the
form.
Again, you want to pass data between view controllers, not views. You can do this quite easily by creating properties on your view controllers that you then set before you push the view controller on the stack. You are already doing this, I think with your item1 property.
What is the correct way to control
memory in this situation? Should I be
popping xib2 from the stack every time
they press the back button? Is so,
what method would I do this?
If you're using a standard UINavigationController to control the navigation stack, you don't need to do anything on your own to manage memory when the user hits the back button; the UINavigationController class will take care of releasing view controllers itself.