I am a little confused, and after countless attempts and read several articles I decided to write.
my problem is that if you call a method from a class (xml) and it is aimed at viewcontroller all goes well
but if I might add [self.view add…] it back to the top reloading the viewDidLoad of the viewController class entering into an endless loop.
this is what I do
class (ViewController)
.h
#import <UIKit/UIKit.h>
@class XMLStuff;
@interface skiSpeedViewController : UIViewController {
}
@property (nonatomic, retain) XMLStuff *xml;
.m
- (void)viewDidLoad
{
[super viewDidLoad];
xml.skiSpeedC = self;
GpsStuff *gps = [GpsStuff alloc];
[gps init];
}
gps.m
- (id)init
{
self = [super init];
if (self) {
xml = [XMLStuff alloc];
}
}
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
[xml lon:newLocation.coordinate.longitude lat:newLocation.coordinate.latitude];
xml.h
#import "skiSpeedViewController.h"
@class skiSpeedViewController;
@interface XMLStuff : NSObject <NSXMLParserDelegate> {
}
@property (retain, nonatomic) skiSpeedViewController *skiSpeedC;
.m
@synthesize skiSpeedC;
- (void) parserDidEndDocument:(NSXMLParser *)parser {
NSLog(@"--%@", self.skiSpeedC); // Return (null)
[self.skiSpeedC riceviDic:datiMeteo];
}
ViewController.m
-(void)riceviDic:(NSMutableDictionary *)dictMeteo {
datiMeteo = [[NSMutableDictionary alloc]initWithDictionary:dictMeteo];
}
}
You are creating a new instance of
classViewControllerevery time. Your “xml” class (XMLStuff?) should have a pointer to the view controller and be calling thericeviDicmethod on that instance.You’re getting an infinite loop because when you allocate the XML object in viewDidLoad, it too starts parsing the XML, then creates more XML objects, which then create more viewControllers…
So, add a property to XMLStuff of type classViewController, and when you create it in viewDidLoad:
Then, in parserDidEndDocument:
UPDATE
OK, after your edit things look very different – you seem to have introduced a new class – GpsStuff, which has its own instance of XMLStuff (and a dodgy looking init method which I assume you haven’t copied in properly?). Which one is actually parsing your document? XMLStuff in your view controller, or in GPSStufF? I’m guessing the one in GPSStuff, which you haven’t set the
skiSpeedCproperty for. I was previously assuming that you were calling everything from your view controller.Why not remove the creation of a new XMLStuff object from GPSStuff, and when you create GPSStuff in your view controller, pass the
xmlobject you’ve created into it:Also, the
skiSpeedCproperty should probably not beretain, since it is essentially a delegate assignment and the view controller is not going to be released before you release the xml parser.As a note, by convention you should be initializing objects like this:
Not on two lines. You want what is returned from
initto be assigned to your variable.