简体   繁体   English

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

[英]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 . 所以你错误在这里,你试图将对象放入期望NSStringretval

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.

相关问题 由于未捕获的异常“ NSInvalidArgumentException”而终止应用程序,原因:“-[SWRevealViewController manifestToggel:] - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SWRevealViewController revealToggel:] 由于未捕获的异常“ NSInvalidArgumentException”而终止应用程序,原因:“-[FBSDKProfilePictureView CGImage]: - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FBSDKProfilePictureView CGImage]: 由于未捕获的异常“ NSInvalidArgumentException”而终止应用程序,原因:“-[MKUserLocation标记]: - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MKUserLocation tag]: 由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [UIButton setText:] - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIButton setText:] 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSCFString isDescendantOfView:]: - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString isDescendantOfView:]: 由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:未知的布局属性' - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: Unknown layout attribute' 由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:NSArrayM objectForKey - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: NSArrayM objectForKey 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSCFBoolean length] - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFBoolean length] 由于未捕获的异常“ NSInvalidArgumentException”而终止应用程序,原因:“-[NSDecimalNumber长度]: - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSDecimalNumber length]: 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[FBSDKApplicationDelegate initializeSDK] - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FBSDKApplicationDelegate initializeSDK]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM