Solved

Best way to pass data between 2 views

Posted on 2011-03-03
4
1,424 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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:   …
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

895 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now