Solved

Best way to pass data between 2 views

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Undo Sync on Iphone 10 58
Drupal - Phonegap - xCode - HELP 3 483
Game Center error 5 657
Creating iOS App with VB6/ASP background 5 170
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

756 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