我正在使用以下方法:
-(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];
}
当qt = comment时,我收到以下错误,应用程序崩溃:
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'
我不确定我做错了什么......当qt等于滑块和textinput时它会起作用...
答案和问题类
import <Foundation/Foundation.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];
}
编辑:请参阅更新代码,这是输出:
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)
更新
现在我甚至没有得到null。我的输出只是:
2011-07-20 01:21:04.402 MainMenu[71910:207] <CommentQuestionViewController: 0x4e0b100>
2011-07-20 01:21:04.404 MainMenu[71910:207] <Question: 0x4e55170>
答案 0 :(得分:2)
您的自定义类型Answer
似乎没有方法setAnswer
。
确保
[[[questionArray objectAtIndex:currQNum-1] question] answer];
返回Answer
类型的对象(它似乎是NSURLCache
类型),然后检查answer
的{{1}}属性是否具有setter方法。< / p>
编辑:要在不发布完整源代码的情况下解决此问题,请从头开始,逐步完成。通过这个,我的意思是按顺序回答以下内容:
Answer
的类型是什么?[questionArray objectAtIndex:currQNum-1]
的类型是什么?[[questionArray objectAtIndex:currQNum-1] question]
的类型是什么?答案 1 :(得分:0)
也许Answer
是NSURLCache
的子类。在自定义子类标头和实现文件中,确保已定义并编写了名为-setAnswer:
的选择器。要么是这样,要么确保在Answer
中存储questionArray
个实例,而不是NSURLCache
个实例。
修改强>
以下内容:
@implementation Answer
@synthesize answer, questionId, entryId;
@end
应该充实。这就是Answer.m
中的全部内容吗?