Hi there,
Im fairly new to the whole world of iPhone dev so forgive me if this is very easy. I have an object Card
that holds 6 Question
objects on it. when I say [card getQuestion:@"Art"]
I am currently returning a Question
object like so
- (Question*) getQuestion: (NSString*) questionType {
Question *q = [questions objectForKey:questionType];
return [q autorelease];
}
Question has a property of text
(type NSString) which allows me to see what the text for the question is. So I want to use this text to update a UILabel in the viewController
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSLog(@"%@", [[self.card getQuestion:@"Art"] qText]);
self.myQuestion.text = [[self.card getQuestion:@"Art"] qText];
}
This crashes the iPhone, whereas if I change the function in object Card
to this
- (NSString*) getQuestion: (NSString*) questionType {
return [[questions objectForKey:questionType] qText];
}
and my call in the viewController to
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSLog(@"%@", [self.card getQuestion:@"Art"]);
self.myQuestion.text = [self.card getQuestion:@"Art"];
}
This works fine.. can anyone explain what I am doing wrong, in both cases the call to NSLog returns me the relevant text. In both cases the display loads but in the first instance it crashes shortly after, whereas the other way it stays stable.
Any help appreciated.