Xcode warning - addObject
I'm using the following method:
-(void) finishQuestionnaire:(id)sender{
NSString * ans;
NSString* qt = [[[questionArray objectAtIndex:currQNum-1] question] qType];
if([qt isEqualToString:@"Slider"]){
ans = [[[questionArray objectAtIndex:currQNum-1] sliderLabel]text];
}else if([qt isEqualToString:@"Option"]){
}else if([qt isEqualToString:@"TextInput"]){
ans = [[[questionArray objectAtIndex:currQNum-1] inputAnswer]text];
}else if([qt isEqualToString:@"ImagePicker"]){
}else if([qt isEqualToString:@"Comment"]){
ans = [[[questionArray objectAtIndex:currQNum-1] inputAnswer]text];
}
//UPDATED
NSLog(@"%@", [questionArray objectAtIndex:currQNum-1]);
NSLog(@"%@", [[questionArray objectAtIndex:currQNum-1] question]);
NSLog(@"%@", [[[questionArray objectAtIndex:currQNum-1] question] answer]);
//[self.navigationController popToRootViewControllerAnimated:YES];
}
when qt = comment, I get the following error and the app crashes:
2011-07-20 00:02:04.723 MainMenu[71393:207] -[NSURLCache setAnswer:]: unrecognized selector sent to instance 0x4e29280
2011-07-20 00:02:04.726 MainMenu[71393:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURLCache setAnswer:]: unrecognized selector sent to instance 0x4e29280'
I'm not sure what I am doing wrong....It works when qt is equal to the slider and textinput...
Answer and Question Class
import <Foundation/Foundation开发者_StackOverflow社区.h>
@interface Answer : NSObject {
//NSString* answerId;
NSString* answer;
NSString* questionId;
NSString* entryId;
}
//@property (nonatomic, retain) NSString* answerId;
@property (nonatomic, retain) NSString* answer;
@property (nonatomic, retain) NSString* questionId;
@property (nonatomic, retain) NSString* entryId;
@end
#import "Answer.h"
@implementation Answer
@synthesize answer, questionId, entryId;
@end
#import <Foundation/Foundation.h>
#import "Answer.h"
@interface Question : NSObject {
NSString* qId;
NSString* qTitle;
NSString* qNumber;
NSString* sectionId;
NSString* qType;
Answer* answer;
}
@property (nonatomic, retain) NSString* qId;
@property (nonatomic, retain) NSString* qTitle;
@property (nonatomic, retain) NSString* qNumber;
@property (nonatomic, retain) NSString* sectionId;
@property (nonatomic, retain) NSString* qType;
@property (nonatomic, retain) Answer* answer;
@end
@implementation Question
@synthesize qId, qTitle, qNumber, sectionId, qType, answer;
-(id)init
{
if (self = [super init])
{
// Initialization code here
answer = [[Answer alloc]init];
}
return self;
}
-(void) dealloc{
[answer release];
[super dealloc];
}
Edit: see update code, here is the output:
2011-07-20 01:21:04.402 MainMenu[71910:207] <CommentQuestionViewController: 0x4e0b100>
2011-07-20 01:21:04.404 MainMenu[71910:207] <Question: 0x4e55170>
2011-07-20 01:21:04.404 MainMenu[71910:207] (null)
Update:
Now I'm not even getting null. My output is just:
2011-07-20 01:21:04.402 MainMenu[71910:207] <CommentQuestionViewController: 0x4e0b100>
2011-07-20 01:21:04.404 MainMenu[71910:207] <Question: 0x4e55170>
Your custom type Answer
does not appear to have a method setAnswer
.
Make sure that
[[[questionArray objectAtIndex:currQNum-1] question] answer];
returns an object of type Answer
(it appears to be of type NSURLCache
), and then check that the answer
property of Answer
has a setter method.
EDIT: To solve this problem without posting your entire source code, start at the beginning and work your way down. By this, I mean answer the following, in order:
- Of what type is
[questionArray objectAtIndex:currQNum-1]
? - Of what type is
[[questionArray objectAtIndex:currQNum-1] question]
? - Of what type is
[[[questionArray objectAtIndex:currQNum-1] question] answer]
?
Perhaps Answer
is a subclass of NSURLCache
. In your custom subclass header and implementation files, make sure you have defined and written a selector called -setAnswer:
. Either that, or make sure you are storing an Answer
instance in questionArray
, and not an NSURLCache
instance.
EDIT
The following:
@implementation Answer
@synthesize answer, questionId, entryId;
@end
should be fleshed out. Is this all you have in Answer.m
?
精彩评论