Solved

Best way to pass data between 2 views

Posted on 2011-03-03
4
1,435 Views
Last Modified: 2012-05-11
I am writing an app with a tab bar with 4 tabs, each tab has a navigation controller to control the views. The first tab is my home view which has a button in the navigation bar that when tapped takes you to the details view. The details view has a back button to take you back to the home view. So for the first tab bar it is like this:

                                                Tab Bar Item 1
                                                          |
                                       HomeNavigationController
                                      /                                          \
                     HomeViewController                  DetailsViewController

At the moment I get data from the database in the HomeViewController and display it in the HomeView. You can then tap a button in the Navigation Bar that takes you to the DetailsView. I'm having trouble accessing the data I got in the HomeViewContoller from the DetailsViewController as it is then out of scope.

Can someone please advise me as to what I am doing wrong. I know the solution will probably be easy and that I'm doing something stupid. I am new to iphone app development and oop programming so please be gentle.

Should I put all the database access code in the HomeNavigationController so that the 2 subordinate views can access that info? I'm trying to work out the best approach but would like some advice before I start tearing my programs apart as they are very nearly working now.
Tags:
0
Comment
Question by:englishchrissy
  • 2
4 Comments
 
LVL 13

Assisted Solution

by:SpeedyApocalypse
SpeedyApocalypse earned 250 total points
ID: 35041748
I would personally check out storing objects in your AppDelegate.  It is always running and is accessible from everywhere.  Check it out: http://www.iphonedevsdk.com/forum/iphone-sdk-development/66286-use-your-app-delegate-share-info-between-objects.html
0
 
LVL 3

Assisted Solution

by:gawhemant
gawhemant earned 250 total points
ID: 35041918
0
 

Accepted Solution

by:
englishchrissy earned 0 total points
ID: 35042166
Thanks guys for the advice. I had actually got this working using a singleton class as described in this post:

http://www.iphonedevsdk.com/forum/iphone-sdk-tutorials/24135-singleton-classes.html

But it was very late last night when I got it working. I immediately had a couple of beers and went to bed very happy.

I will check out the links you provided as I am well aware there are always more than one way to do things and I want to do things the best way. Very simple when you know how but strange that the techniques are not mentioned at all in both the iphone books I have: Beginning iPhone 3 Development and Sams iPhone Application Development in 24 Hours. Which incidentally are both very good.

Guess I'll have to split the points. So thanks guys for your time.
0
 

Author Closing Comment

by:englishchrissy
ID: 35081170
Opps, See my comment above. Cheers
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Mac .htaccess textedit problem 8 475
Where & how to install Amazon Kindle app on iPad 13 1,142
Compiling Sass Command Line Mac OS X 8 826
OPINION - Going to write an App 3 86
Preface   In the first 100 days of the Macintosh release in January 1984, Apple sold 72,000 of the computers. Relatively cheap, easy-to-use personal computer with a graphical operating system. I've never seen this model. I did see this one:   …
Do you come here a lot? Are you lazy like me and don't want to go through the "trouble" of having to click your Dock's Safari icon and then having to click your Experts Exchange Favorites bookmark to get here? Well then this article is for you.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question