Take the 2-minute tour ×

If someone can help this would be awesome.

So I have MainViewController files and there is a class that is declared there. the class name is @MountianItem when i change views the data is being stored in the fist view but when i move to the third view the data is empty. I am clueless on this. I know I am missing something


#import <UIKit/UIKit.h>
#import "DetailViewController.h"
#import "DetailMapController.h"

@interface MainViewController : UIViewController <NSXMLParserDelegate, UITableViewDelegate, UITableViewDataSource>
    UIButton                *searchButton;
    UIActivityIndicatorView *activityIndicator;
    UITableView             *resultsTableView;
    UILabel                 *elevationLabel;
    UISlider                *elevationSlider;

    NSURLConnection         *urlConnection;
    NSMutableData           *receivedData;

    NSXMLParser             *xmlParser;

    NSMutableArray          *mountainData;

    DetailViewController    *detailView;
@property (nonatomic, retain) IBOutlet UIButton                 *searchButton;
@property (nonatomic, retain) IBOutlet UIActivityIndicatorView  *activityIndicator;
@property (nonatomic, retain) IBOutlet UITableView              *resultTableView;
@property (nonatomic, retain) IBOutlet UILabel                  *elevationLabel;
@property (nonatomic, retain) IBOutlet UISlider                 *elevationSlider;

@property (nonatomic, retain) NSURLConnection *urlConnection;
@property (nonatomic, retain) NSMutableData *receivedData;

@property (nonatomic, retain) NSXMLParser *xmlParser;

@property (nonatomic, retain) NSMutableArray *mountainData;

@property (nonatomic, retain) DetailViewController *detailView;

- (IBAction) startSearch:(id)sender;
- (void) setUIState:(int)uiState;
- (IBAction)sliderChanged:(id)sender;

- (NSString *) getCommaSeparatedFromStringContainingNumber:(NSString *)stringWithNumber;



#import "MainViewController.h"
#import "MountainItem.h"

@implementation MainViewController

@synthesize searchButton;
@synthesize activityIndicator;
@synthesize resultTableView;
@synthesize elevationLabel;
@synthesize elevationSlider;

@synthesize urlConnection;
@synthesize receivedData;

@synthesize xmlParser;

@synthesize mountainData;

@synthesize detailView;

// State is loading data. Used to set view.
static const int LOADING_STATE = 1;
// State is active. Used to set view.
static const int ACTIVE_STATE = 0;

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    return self;

- (void)dealloc
    [searchButton release];
    [activityIndicator release];
    [resultTableView release];
    [elevationLabel release];
    [elevationSlider release];
    [urlConnection release];
    [receivedData release];
    [xmlParser release];
    [mountainData release];
    [detailView release];
    [super dealloc];

#pragma mark - NSXMLParser Callbacks
    //Is a mountain_item node
    if ([elementName isEqualToString:@"river"])
        MountainItem *mountainItem = [[MountainItem alloc] init];
        mountainItem.name = [attributeDict objectForKey:@"name"];
        mountainItem.gage = [attributeDict objectForKey:@"gage"];
        mountainItem.latitude = [attributeDict objectForKey:@"latitude"];
        mountainItem.longitude = [attributeDict objectForKey:@"longitude"];

        [mountainData addObject:mountainItem];

        [mountainItem release];
        mountainItem = nil;




#import <UIKit/UIKit.h>
#import "MountainItem.h"

@interface DetailViewController : UIViewController {
    UITextView *mountainInfoTextView;
    UIWebView *myWebViewer;
    UIBarButtonItem *addButton;

    MountainItem *mountainItem;

@property (nonatomic, retain) IBOutlet UITextView *mountainInfoTextView;
@property (nonatomic, retain) IBOutlet UIWebView *myWebViewer;
@property (nonatomic, retain) IBOutlet UIBarButtonItem *addButton;

@property (nonatomic, retain) MountainItem *mountainItem;



#import "DetailViewController.h"
#import "DetailMapController.h"

@implementation DetailViewController
@synthesize mountainInfoTextView;
@synthesize mountainItem;
@synthesize myWebViewer;
@synthesize addButton;

- (void)dealloc {
    [mountainInfoTextView release];
    [mountainItem release];
    [myWebViewer release];
    [super dealloc];

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self setTitle:mountainItem.name];
    NSMutableString *myHttp;
    myHttp = [@"http://water.weather.gov/resources/hydrographs/" mutableCopy];
    [myHttp appendString:mountainItem.gage];
    [myHttp appendString:@"_hg.png"];
    NSString *urlAddress = myHttp;
    NSURL *url = [NSURL URLWithString:urlAddress];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [myWebViewer loadRequest:requestObj];

    //mountainInfoTextView.text = [NSString stringWithFormat: @"Name: %@",mountainItem.gage]; 


#import <UIKit/UIKit.h>
#import "MapKit/Mapkit.h"
#import "DetailViewController.h"

@interface DetailMapController : UIViewController <MKMapViewDelegate> {
    MKMapView *MyMapLocation;
    MountainItem *mountainItem;

@property (nonatomic, retain) IBOutlet MKMapView *MyMapLocation;
@property (nonatomic, retain) MountainItem *mountainItem;



#import "DetailMapController.h"
#import "MapAnnotation.h"

@implementation DetailMapController
@synthesize mountainItem;
@synthesize MyMapLocation;

- (void)dealloc
    [MyMapLocation release];
    [mountainItem release];
    [super dealloc];

    [super viewWillAppear:animated];
    [MyMapLocation setMapType:MKMapTypeStandard];
    [MyMapLocation setZoomEnabled:YES];
    [MyMapLocation setScrollEnabled:YES];
    region.center.latitude = [mountainItem.latitude doubleValue] ;
    region.center.longitude = [mountainItem.longitude doubleValue] ;
    //region.center.latitude = [@"36.273889" doubleValue] ;
    //region.center.longitude = [@"-86.816944" doubleValue] ;
    region.span.longitudeDelta = .001f;
    region.span.latitudeDelta = .001f;
    [MyMapLocation setRegion:region animated:YES];

    [MyMapLocation setDelegate:self];
    [self.MyMapLocation removeAnnotations:self.MyMapLocation.annotations];
    MapAnnotation *ann = [[MapAnnotation alloc] init];
    ann.title = mountainItem.name;
    ann.coordinate = region.center;
    [MyMapLocation addAnnotation:ann];
    [MyMapLocation selectAnnotation:ann animated:YES];
    [ann release];

- (void)viewDidUnload
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    self.MyMapLocation = nil;
    //self.mountainItem = nil;

When I debug in DetailMapController mountainItem is empty.

Any help would be greatly helped!

I overlooked this part. the two files that sets mountainItem


   #import <Foundation/Foundation.h>

@interface MountainItem : NSObject 
NSString *name;
NSNumber *gage;
NSString *elevationAsString;
NSNumber *latitude;
NSNumber *longitude;

@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSNumber *gage;
@property (nonatomic, retain) NSString *elevationAsString;
@property (nonatomic, retain) NSNumber *latitude;
@property (nonatomic, retain) NSNumber *longitude;



@implementation MountainItem
@synthesize name, gage, elevationAsString, latitude, longitude;

share|improve this question
Way too much code. Isolate the problem to a few lines of code or a method. –  wadesworld Jun 29 '11 at 17:03
I do not see any code that actually creates and show the other view controllers, nor do I see any code that sets the mountainItem on the classes –  Joe Jun 29 '11 at 17:11
@wadesworld - if I could isolate the problem to a few lines of code why would I be posting it here. I was trying to give a good understanding of what it being done. –  Darren Chaney Jun 29 '11 at 21:03
add comment

closed as too localized by C. A. McCann, Mat, JB King, Bo Persson, yoda Jun 30 '11 at 22:30


1 Answer

Firstly, you have posted far too much code here - this site isn't really for posting your applications and getting people to debug it for you!

The problem you have is that you are not creating an instance of mountainItem in your DetailMapController. How do you expect it to not be nil if you aren't creating an instance of it?

share|improve this answer
Nick, thanks for the note, although this is Class that is being pulled in. Could you define a little more that you are talking about. thanks. –  Darren Chaney Jun 30 '11 at 14:30
What do you mean "this is Class that is being pulled in"? –  Nick Bull Jun 30 '11 at 14:52
This class is being set in MountainItem.h although what I don't understand is that it's readable with data in DetailViewController.m but looses data when DetailMapController.m is viewed. I am stumped on this one. –  Darren Chaney Jun 30 '11 at 20:02
I was really hoping that I wouldn't have spent two days trying to figure this out and haven't made any progress. Just stressed! –  Darren Chaney Jun 30 '11 at 20:02
DetailViewController and DetailMapController are two different classes and you aren't using it as an instance variable nor are you passing it between the classes. Are you new to Objective-C (and OOP in general)? –  Nick Bull Jun 30 '11 at 20:24
show 5 more comments
