我从网络服务中获取数据:
//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
}
我尝试在选择器视图中填充的所有日期都会出现异常。
选择器视图委托:
- (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;
}
我的网络服务示例:
{
"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是NSObject的子类
请帮忙。
答案 0 :(得分:1)
retval.text = [quesArray objectAtIndex:row];
您正在访问quesArray
。
其中:[quesArray addObject:objHome];
objHome是:Home *objHome=[[Home alloc] init];
所以你错误在这里,你试图将对象放入期望retval
的{{1}}。
您需要使用以下内容:
NSString
答案 1 :(得分:1)
retval.text = [quesArray objectAtIndex:row];
您的retval.text
是一个字符串,并且您正在为其指定一个对象
你可以这样做
Home *newHome=[quesArray objectAtIndex:row];
retval.text=newHome.homeQuesTxt;
答案 2 :(得分:0)
quesArray
填充了Home
个对象
Home *home = quesArray[row];
retval.text = home.homeQuesTxt;