?
Solved

Best way to pass data between 2 views

Posted on 2011-03-03
4
Medium Priority
?
1,471 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 13

Assisted Solution

by:SpeedyApocalypse
SpeedyApocalypse earned 1000 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 1000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

CocoaPods is the best way to manage library dependencies in iOS and OS X projects. By using cocoa pods there is no need of downloading the code from github and copying to your project. There are plenty of open source libraries now available with C…
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 tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

752 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