Best way to pass data between 2 views
Posted on 2011-03-03
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
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.