[英]Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Home isEqualToString:]
I am fetching data from a web service: 我从Web服务获取数据:
//temp1 is NSDictionary
//responseArr1 is NSMutableArray
for(temp1 in responseArr1).......,
{
quesTxt = [[temp1 objectForKey:@"question_text"] stringByReplacingOccurrencesOfString:@"%PROFILENAME%" withString:del.onlyFirstName];
quesID = [temp1 objectForKey:@"idlife_stage_question"];
Home *objHome=[[Home alloc] init];
objHome.homeQuesTxt = quesTxt;
objHome.homeQuesID = quesID;
[quesArray addObject:objHome];
//[quesArray addObject:[[temp1 objectForKey:@"question_text"] stringByReplacingOccurrencesOfString:@"%PROFILENAME%" withString:del.onlyFirstName]];//this works fine
}
All the date when i try to populate in picker view it gives exception. 我尝试在选择器视图中填充的所有日期都给出了异常。
picker view delegate: 选择器视图委托:
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
UILabel *retval = (id)view;
if (!retval) {
retval= [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [pickerView rowSizeForComponent:component].width, [pickerView rowSizeForComponent:component].height)];
}
retval.text = [quesArray objectAtIndex:row];.........// **EXCEPTION HERE**...
retval.font = [UIFont boldSystemFontOfSize:14];
retval.numberOfLines = 3;
return retval;
}
sample of my web service: 我的网络服务样本:
{
"idlife_stage_question" = 35;
"life_stage_idlife_stage" = 1;
"profile_idprofile" = 0;
"question_text" = "When %PROFILENAME% first smiled?";..//%PROFILENAME% replaces with user name which i have
sequence = 34;
}
Home is a subclass of NSObject Home是NSObject的子类
Please help. 请帮忙。
retval.text = [quesArray objectAtIndex:row];
Here you are accessing quesArray
. 在这里,您正在访问
quesArray
。
Which is as : [quesArray addObject:objHome];
其中:
[quesArray addObject:objHome];
And objHome is : Home *objHome=[[Home alloc] init];
objHome是:
Home *objHome=[[Home alloc] init];
So you error is here, you tried to put the object into the retval
which expects an NSString
. 所以你错误在这里,你试图将对象放入期望
NSString
的retval
。
You need to use something as : 您需要使用以下内容:
retval.text = [[quesArray objectAtIndex:row] homeQuesTxt]; //or anyother property that you want to show in text
retval.text = [quesArray objectAtIndex:row];
Your retval.text
is a string and you are assigning it an object 你的
retval.text
是一个字符串,你正在为它指定一个对象
You could do like this 你可以这样做
Home *newHome=[quesArray objectAtIndex:row];
retval.text=newHome.homeQuesTxt;
The quesArray
is populated with Home
Objects quesArray
填充了Home
Objects
Home *home = quesArray[row];
retval.text = home.homeQuesTxt;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.