Pick value from IPhone tableview - iphone

I have just started developing iphone applications, but now i'm stuck with this problem, my problem is,
how to pick a data from table view and bring it back to previous view.
if you can give me a sample code that would be really appreciated.
Thank in advance,
prasad.

I don't think altering AppDelegate will be a good practice although it will work. You should prefer creating a Model class where you can create a variable and set its value in your table. When you go back to previous view you can use the same variable which contains the selected table value.
Good luck..!!

You can make an object in App Delegate class.set its value as the value picked from tableview in the table view class.In the previous class you can make an object of app delegate class & access that particular object whose value was set with the value picked from table view

Related

Using data between any controller

I have spent hours trying to use a set a tableViewCell from a picker selection in another view. I have posted two questions, that brought no answers. So i decided to approach it differently. I tired making a global variable, but then figured out, I had to make a dataClass file which wouldn't work for me because I have to use a viewController. Im beginning to lose hope. Is their any way to set the title of a table view cell from another view? Im not looking for a giant chunk of code, just a place to start. The way to actually do it, if its possible. Thanks in advance.
Yes, this is definitely possible. In Model-View-Controller systems all information sharing happens through your model class. Make it a singleton object (singleton is similar to global variables, but it has proper initialization).
Create a class with the data that must be shared. Create a class method of that class to produce the sole instance of that class. Define and initialize a static variable holding that instance. Use dispatch_once to initialize that instance. Here is an answer illustrating this approach.
With a singleton instance in place, all your view controllers can access the model as necessary. One view controller can set properties of the model, so that when the other view controller comes along, the data is ready for it to process.

Re-initialising a view after the save button has been touched

I have a TabBar Application with 2 tabs saving/fetching data to and from CoreData. The problem that I am having is that when the form has been filled and the user has touched the save button the view is not re-loaded or re-initialised. All I want is for the view to be ready for the user to repeat the process with the next set of information. I am probably not thinking about this in the correct way so a pointer in the right direction would be very much appreciated...
Do I need to manually set everything including the managedObjectContext etc. to nil? Or is there something that I can do with methods like viewWillDisappear that will elegantly help me to "re-initialise" that specific tab?
I ave read up the Apple docs on view hierarchies, and life cycles but I just seem to have confused myself...
Thanks in advance for any suggestions, referrals to code or even recommendations on relevant reading material.
It sounds like what you want to do is reload any data to their default states when the user taps a button. Unfortunately, you'll have to do this manually, setting each IBOutlet's value to a meaningful default (probably the empty string).
There are two ways I can think of that would help make this more elegant:
Use an IBOutletCollection and fast enumeration to loop over all the IBOutlets and not have a bunch of code to do each one individually.
If you're switching tabs in between these events, you can something neat and use your app delegate as your UITabBarControllerDelegate for the tabBarController:didSelectViewController: to call the clearing-out method for you instead of relying on viewDidAppear.

Using KVO to reload data in UITableView

I've been expanding my horizons recently and am trying to start utilizing KVO more in my programming.
I have a view controller in my iPhone application which acts as the datasource and delegate for a UITableView. I also have a singleton model controller which coordinates populating my model with data fetched from the web.
In my view controller, I request that the model's controller load new data from the web. Then I can observe the "dataset" property of the singleton and receive KVO notifications when items are added to or removed from the set.
Now, each cell in my table view has an indicator which specifies whether the content in that cell has been read or not (like the blue "unread" dot in mail). Like mail, when a row is selected, I'll display details about that row. In the viewDidLoad for the detail view, I set the object's "read" property to YES. I would like the original view controller to be able to observe this "read" property of each object in the dataset, so that [tableView reloadData] can automatically be called as necessary and redraw the cells without the blue dot.
In researching this, I found the following link: http://homepage.mac.com/mmalc/CocoaExamples/controllers.html#observingACollection
According to this, it looks like I will do the following:
1) Be an observer of the array
2) Whenever I get a notification of a change to the array, I add (or remove) myself as an observer for the individual properties I am interested in.
3) When I get a notification of a change to the property I'm interested in, I can call [tableView reloadData]
I'm currently in the process of attempting to implement this approach. Can anyone with experience doing this offer some advice on this approach? If this the best way to handle this type of situation?
If this is the correct approach, would anyone be willing to share their implementation of adding/removing the observers for objects in the collection when the collection changes?
Thanks!
I think you can accomplish this task by using Core Data and the Fetched Results Controller.
I'm sure this can save you a lot of work.
Here's a good guide: Ray Wenderlich Core Data Tutorial, getting started

Keeping data in a UIViewController, even after go to a TablevViewController and come back?

I have a UIViewController with some UITextFields in it which holds username and other details. And i need to go to another view, which is a UITableView which holds the list of countries to user to choose and get back to the UIViewController again, when user picks one.
What my problem is i will lose all my data mentioned previously in the UIViewControl, when get back from UITableView. I can use application's delegate to store data when go to UITableView and load them back when UIViewController is loaded again.
I was wondering, whether is there a way to achieve my goal, other than this approach? I have to use number of variables in the delegate to store these data as there are many.
Can anyone help me out with an idea please???
I dont think.But I think you are reloading the table in viewWillAppear.Thats why ur older values are not remaining

Passing Non-Static Objects Between View Controllers

I'm a newb to iphone development and objective c, but hoping some folks smarter than me can lend a hand. Here's my problem:
I have a view based app with about 7 different view controllers. The user navigates via a bottom tab bar. I have the users entering data in the first view controller to an object named "copies". I need to get the copies value to another controller so it can be used for calculations. This needs to be done for many objects in the apps other controllers too.
Example:
User enters Copies value in 1st view controller.
User enters Price value in 6th view controller.
7th view controller calculates copies x price = grand total
In my research I worked out the singleton method, but that seems limited to static data.
What's the best way to ensure that another view controller can access an object the user has filled in? I'm trying to avoid going a SQLite route currently. I want to stick to something basic and work my way up in complexity. Does anyone have any sample code I can review? It really helps to see how others have tackled this before.
Thanks in advance!
If I've understood you correctly there is just one copies value and one price value in the whole app. If that is the case...
There are many ways to do this. Easiest way (perhaps): you could make a Singleton object of a class that you define that has copies and price as properties. Singleton in Objective-C is here, and you would define your properties within the Singleton class. Then you would just call its shared instance and use the values on that. So your code would look like this:
[ThatCrazySingleton sharedInstance].copies = 5;
for writing.
Hope this is what you're looking for.
If you don't want to use a Singleton, at some point one of the UIViewControllers would need to send a message to the others with the copies and price values (hopefully wrapped up ["encapsulated"] in an object). This means that you have to get a reference to the other View controllers, which you can always do by going through the hierarchy.