Ios 由于未捕获异常而终止应用程序';NSInvalidArgumentException';,原因:'-[主isEqualToString:]

Ios 由于未捕获异常而终止应用程序';NSInvalidArgumentException';,原因:'-[主isEqualToString:],ios,objective-c,nsmutablearray,nsdictionary,uipickerview,Ios,Objective C,Nsmutablearray,Nsdictionary,Uipickerview,我正在从web服务获取数据: //temp1 is NSDictionary //responseArr1 is NSMutableArray for(temp1 in responseArr1)......., { quesTxt = [[temp1 objectForKey:@"question_text"] stringByReplacingOccurrencesOfString:@"%PROFILENAME%" withString:del.onlyFirstName];

我正在从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

        }
{
        "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;
    }
当我尝试在picker视图中填充所有日期时,它会给出异常

选择器视图委托:

- (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;
}
我的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

        }
{
        "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的一个子类

请帮忙

retval.text = [quesArray objectAtIndex:row];
您正在访问
quesArray

这是:
[quesArray addObject:objHome]

objHome是:
Home*objHome=[[Home alloc]init]

错误就在这里,您试图将对象放入
retval
中,它需要一个
NSString

您需要将某物用作:

retval.text = [[quesArray objectAtIndex:row] homeQuesTxt]; //or anyother property that you want to show in text
您的
retval.text
是一个字符串,您正在为其分配一个对象

你可以这样做

 Home  *newHome=[quesArray objectAtIndex:row];

  retval.text=newHome.homeQuesTxt;

quesArray
中填充了
Home
对象

Home *home = quesArray[row];
retval.text = home.homeQuesTxt;

将断点放在代码上,并跟踪正确的崩溃点?向我们显示崩溃代码…您的Label.text是一个字符串,您正在为其分配一个对象。我同意@nsgulliver@nsgulliver:即使我同意,这也是我刚才回答的:)我已经提到retval.text=[quesArray objectAtIndex:row];……//这里出现异常…谢谢,现在它显示数据,但当我滚动选取器时,它会引发另一个异常:由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'-[\uu NSCFConstantString homeQuesTxt]:未识别的选择器发送到实例0x1E72A8 HERE..retval.text=newHome.homeQuesTxt;检查如何在Home类中定义homeQuesTxt.like..@property(非原子,强)NSString*homeQuesTxt;您应该调试代码或设置断点,在赋值之前尝试将值强制转换为(NSString*)。另外,请检查您的标签是否未解除分配。嘿,Anoop,这对我很有帮助,但我还需要在数组中插入一个自定义行,该行每次在数组末尾都会显示。我该怎么做?@user2268539:数组中的自定义行是什么?你想在那里添加一些文本吗?是的……比如“创建你自己的问题”,但我正在使用[[quesArray objectAtIndex:row]homeQuesTxt]在选择器中显示数据??uipicker是视图,你需要添加到模型中。