Solved

Best way to pass data between 2 views

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

758 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

22 Experts available now in Live!

Get 1:1 Help Now