0
votes

I am fetching data from a web service:

//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

Please help.

3
Put break point to your code and trace correct crashing point ? Show crash code to us... - Mani
your Label.text is a string and you are assigning it an object. - nsgulliver
i agree with @nsgulliver - Dipen Panchasara
@nsgulliver: even i agree, that is what i just answered :) - Anoop Vaidya
i have already mentioned that retval.text = [quesArray objectAtIndex:row];.........// EXCEPTION HERE... - user2268539

3 Answers

1
votes
retval.text = [quesArray objectAtIndex:row];

Here you are accessing quesArray.

Which is as : [quesArray addObject:objHome];

And objHome is : Home *objHome=[[Home alloc] init];

So you error is here, you tried to put the object into the retval which expects an NSString.

You need to use something as :

retval.text = [[quesArray objectAtIndex:row] homeQuesTxt]; //or anyother property that you want to show in text
1
votes
retval.text = [quesArray objectAtIndex:row];

Your retval.text is a string and you are assigning it an object

You could do like this

 Home  *newHome=[quesArray objectAtIndex:row];

  retval.text=newHome.homeQuesTxt;
0
votes

The quesArray is populated with Home Objects

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