Hi,
I've got a problem with my app crashing in the simulator without any error message.
Basically I have a view which reads in an XML, parses it then on a button click calls another view which displays some of the parsed information. I'm an ActionScript developer so I took the same approach I would have taken in Flash to save the parsed information - I created a custom object with a property for each piece of information then put all the custom objects in an array.
-- Code for the custom object:
This works fine and the object is created as expected.
When I pass the array to the second view, it can read the objects, but as soon as I try to access a property the app crashes with no error message in the debugger.
Here's the piece of code that accesses the object and the various different things I've tried to access it with their respective results:
Is my approach totally off? Should I be writing this object to disk or something? I suspect the crash is due to some sort of memory violation but without an error message I'm stumped. Or would I be better off just saving all this information in a dictionary?
Thanks in advance,
Caroline.
I've got a problem with my app crashing in the simulator without any error message.
Basically I have a view which reads in an XML, parses it then on a button click calls another view which displays some of the parsed information. I'm an ActionScript developer so I took the same approach I would have taken in Flash to save the parsed information - I created a custom object with a property for each piece of information then put all the custom objects in an array.
-- Code for the custom object:
Code:
#import "Posizione.h"
@implementation Posizione
@synthesize collezione; // will be set by calling object
@synthesize path; // ditto
@synthesize img;
@synthesize titolo;
@synthesize tipomanichini;
@synthesize tipologia;
@synthesize xNode;
@synthesize descrizione;
- (id)initWithNode:(CXMLElement *)node {
// Assign self to value returned by super's designated initializer
// Designated initializer for NSObject is init
NSLog(@"init posiizione");
self = [super init];
xNode = node;
titolo = [[xNode attributeForName:@"titolo"] stringValue];
img = [NSString stringWithFormat:@"%@/%@", path, [[xNode attributeForName:@"img"] stringValue]];
tipologia = [[xNode attributeForName:@"tipologia"] stringValue];
tipomanichini = [[xNode attributeForName:@"tipomanichini"] stringValue];
descrizione = [xNode stringValue];
[self sayHello];
[self sayHelloTitle];
return self;
}
-(void)sayHelloTitle{
NSLog(@"hello %@", self.titolo);
}
-(void)sayHello{
NSLog(@"hello");
}
- (void)dealloc {
[collezione release];
[path release];
[img release];
[titolo release];
[tipomanichini release];
[tipologia release];
[xNode release];
[descrizione release];
[super dealloc];
}
@end
When I pass the array to the second view, it can read the objects, but as soon as I try to access a property the app crashes with no error message in the debugger.
Here's the piece of code that accesses the object and the various different things I've tried to access it with their respective results:
Code:
for (int i=0; i<[nArray count]; i++) {
Posizione *pos = [nArray objectAtIndex:i];
[pos sayHello]; // works
[pos sayHelloTitle]; // causes an exit with no error
NSLog(@"pos: %@", [nArray objectAtIndex:i]); // Returns <Posizione: 0x64787b0>
//NSLog(@"pos img: %@", pos.img); // causes crash with no error
}
Is my approach totally off? Should I be writing this object to disk or something? I suspect the crash is due to some sort of memory violation but without an error message I'm stumped. Or would I be better off just saving all this information in a dictionary?
Thanks in advance,
Caroline.