store selected item in ram in ui tabbar objective-c - ios

I'm new to ios. I'm uising uitabbar. I want to store in ram only currently selected viewcontroller of the secific UItabbarControllerItem is there a way to implement it?
UITabbar is loading all viewcontrollers in ram. I don't like it. I want to make it work following way: store in memory only 1 selected viewcontroller,
when user selects othe uitabbar item it loads again new viewcontroller

Are you sure you wanna do this? IOS is responsible for managing memory, but try this.
When you load a controller you can make a loop over "controllers" property of the tabbar and put a nil value to each. Be careful, don't put your current controller = nil.
tabbar.controllers is an array with the all the controllers of the tabbar. If you are in the second one, is the tabbar.controllers[1], don't put this one to nil.
If you want to go to other controller, you have to create it an assign to the tabbar.controllers. But, which position? the array only have one position, the current controller, and almost certainly will not work tabbar buttons. It will generate an exception and your app fall.
I do not recommend you do this, but yourself

Related

Passing through Segues, Determining what view the user is on and NavigationController buttons not appearing

Sorry for the long and possibly confusing question. In this I have 2 main problems with my code, those being: 1- When I embed my viewControllers in a UINavigationController and add a bar button item, nothing appears, yet it appears when I add it to the pageViewController. Secondly, I am wondering if there is a way to do this differently and use one button on the pageView (which appears on all viewcontrollers in it) and just determine what the user was looking at when they pressed the button and are taken to another viewcontroller.
I am trying to build a page-based application, and I have set up the application with 7 view controllers (One for each day of the week). I then have an AddViewController, where users can add data to a certain day. I was wondering if there is a way to only use 1 addView linked to the NavBar on the PageViewController, as when I embed all other viewControllers and add a bar button, it does not show up.
With the pageViewController being embedded, this is what it looks like with a bar button on it.
This then leads to:
Which works well, however I am wanting to pass data to various arrays (one for each viewController), and I want to know which ViewController the user wishes to add to (based off what day they were on). Is there a way to determine this and then unwind to the viewController and append the right data to the right array or should I have one addView per dayViewController? If that is the case, I am coming across the issue whereby the bar button items do not appear on the viewControllers when they are embedded in a navigationController. It looks like this:
StoryBoard: (Example: MondayViewController)
The outcome is a missing barButton: (Keep in mind I changed the tint Colour to white so it would be visible)
I was wondering if anyone has the answer to either of my problems, and once again, thanks for taking the time to look at this array of questions in one problem.
Any suggestions are welcome !
Rowan,
You can do this:
Create an UINavigationViewController and then embed an UIPageViewController in it.
In the data source for the UIPageViewController implement these two methods:
- pageViewController:viewControllerBeforeViewController:
- pageViewController:viewControllerAfterViewController:
Here you will return the correct instance of your DayViewController for each position (or nil if you are on the first/last page). Your data model would also be set here.
Add your "Add" bar button to the navigation bar of the UIPageViewController and let it push your AddViewController. When pushing the AddViewController provide to it the info on which day is currently visible. You will probably need to keep track of this your self. Use the - pageViewController:didFinishAnimating:previousViewControllers:transitionCompleted: method of the UIPageViewController delegate.

Change view controller cause reset changes

I have two view controller. On the Second controller I have a button which cause a UILabel to change from "larry" to the string "happy". If I press back, which take me to first view controller, and then forward, which take me to the second view controller (from the first view controller). I found that the UILabel change back to default, "larry". How do I make it so that when I change view controller, the changes and data doesn't get clear away.
Recap: How to make it so that every change in a view controller doesn't change back to default after changing to another view controller.
This doesn't only happen with UILable, it also happen with
self.loadPage.hidden = YES;
I also found out what I made to turn 'hidden' also appear back after I pressed back and forward.
Thank
The problem that you are facing is due to the fact that when you press the button a new instance of the second viewcontroller is created and that old one is destroyed.
If you want to persist the data while pressing the buttons, you need some way to store the information somewhere
there are some methods to got about it
You can use instance variables in both the classes to store the data temporarily and display them. You need to know the concept of protocols and delegates for this as well.
You can store the information in NSUserDefaults for some moment so that you can access it later on.
The issue is each time when you goes from first view controller to second, you are initialising a new instance of second view controller which brings back every values you changed to default values.
You need to save the values elsewhere and assign those values whenever control is switched from one view controller to another

Multiple States in Xcode 6 Storyboard. Animating/Moving items in run time

I have made various attempt to go storyboard only and limit my code when it comes to UI. Everytime I was getting stuck and reverting back to code. Since the release of XCode 6 and the new iPhone that have multiple screen sizes it make more sense that ever to go Storyboard only.
This time I am stuck on the following scenario. I want to create a custom search view controller that will have 2 states:
Search State. It will prompt the user for a keyword to search.
Result State. It will display the results to the user.
I am aware that this can be accomplished using the UISearchController, but the customer wants to customise the behaviour. Currently I have two view controllers and a push/show segue between them. I would like to replace that with one view controller and animate the display of the results.
Is there any way that storyboard can accomplish that. I am thinking of creating two view controllers (in storyboard) with different layouts. Both will be linked on the same class. I could create a segue between them, but then I will lose all the variable stored inside them and will not be able to animate between them.
On the transition between the two states some UI elements will be hidden and some others will be moved. I would like that to be animated.
I know how to do that in code without using storyboard, but then I will have to cover all different screen scenarios. I hope there is an alternative way.
You can do this with two view controllers, and set a segue between them. The trick is that the animation bit will have to be done in code, unless you write a custom UIStoryboardSegue to handle the animation.

Multiple Segues to one ViewController with NavigationController?

i have one question about using multiple segues to one ViewController. Ill try to create an article management, so you can add/edit/delete articles.
When you add a new article you can choose between a maincategory and a subcategory, choose the article and then edit some inital values.
but if ill try to edit one of my selected articles, i would like to jump to the "latest" ViewController in navigation stack.
I thought i could easily create another segue to my last viewController, but ill always get an error when i try to load this segue (i guess this could be a problem with the existing NavigationController).
I could provide some code, but i dont know if this is a possible solution to solve such things - or is there a better way?
Thanks in advance.
You can, but the new segue should take you to a navigation controller that just contains the last view controller (as the root). In this way you are duplicating the normal situation but with only 1 view controller.
If you wanted to allow the last view controller to have a 'back' button which took you to some 'earlier' screens (if that makes any kind of sense in your app) then you would need to write some code. It's more likely that other screens should be accessed via bar button items or similar (which would also likely be done in code).

iPhone app, how to handle the back button with dynamic content

I have a tab bar controller view that loads a record from an api call. Since different data is shown for the same record on each tab I'm storing the object in the app delegate and just grabbing it on viewDidLoad.
The problem I'm running into is that this record is related to other records, and one of the tabs has the other records listed. So if you click on one of those it needs to essentially reload the same tab bar controller.
I'm going to reload the same controller using the instantiateViewControllerWithIdentifer method, but how would the back button work on this since if it went back that object is now gone.
My thoughts on reloading old objects was to keep an array of all the ids of the records loaded, and just go back to the last id and reload the object from the api.
For what you are trying to do, I would suggest creating your own custom implementation of a tab bar controller. By doing this you will be able store the data from each record as a property in your custom tabbar controller. You can then have multiple instances of your tab bar controller, each with its own data (and you won't have to store anything in your app delegate, which ideally shouldn't be used for this purpose anyway.)
Here is an example tutorial in which the author creates a custom tab bar controller similar to what you would need:
http://www.iphonedevcentral.com/create-uitabbarcontroller/

Resources