Sai
Sai

Reputation: 59

Displaying images from JSON Url into tableview

am getting the 3 errors for this

1) " [__NSCFString size]: unrecognized selector sent to instance "

2) " [NSNull length]: unrecognized selector sent to instance "

3) " [__NSCFString size]: unrecognized selector sent to instance "

below is my code. could you please help me to love this issue.

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:  (NSInteger)section {
    return matchesProfileArr.count;;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    displayCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier
    forIndexPath:indexPath];

    if(!cell) {
        cell = [[displayCell alloc] initWithStyle:UITableViewCellStyleDefault
        reuseIdentifier:CellIdentifier];
    }

    NSMutableDictionary *dict= [matchesProfileArr objectAtIndex:indexPath.row];            
    NSMutableDictionary *dictdetails=[dict objectForKey:@"ABSAdvancedSearch"];

    cell.lblAge.text = [dictdetails objectForKey:@"age"];
    cell.lblLocation.text = [dictdetails objectForKey:@"CustomerCity"];
    cell.lblProfession.text = [dictdetails objectForKey:@"rb_profession_title"];
    cell.lblEducation.text = [dictdetails objectForKey:@"rb_education_title"];
    cell.lblFullName.text = [dictdetails objectForKey:@"Username"];
    cell.profileImage.image = [dictdetails objectForKey:@"profile_pic"];

    return cell;
}

Upvotes: 1

Views: 102

Answers (3)

Shamsiddin Saidov
Shamsiddin Saidov

Reputation: 2281

Just addition to the @Stefan and @balkaranSingh's answers. I think your @"age" key is holding NSNumber not NSString, for this reason convert it into string.

cell.lblAge.text = [[dictdetails objectForKey:@"age"] stringValue];

Upvotes: 0

Stefan
Stefan

Reputation: 1335

You are sending string to the image. You must load image from url like this:

NSString *urlImage = [dictdetails objectForKey:@"profile_pic"];
cell.profileImage.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:urlImage]]];

EDIT: This is synchronous image loading.

I would like you to suggest you to user AFNetworking method for loading image from URL:

[cell. profileImage setImageWithURL:[NSURL URLWithString:urlImage]placeholderImage:[UIImage imageNamed:@"someImage"]];

OR:

dispatch_async(dispatch_get_main_queue(), ^{

        cell.profileImage.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:urlImage]]];
    });

Upvotes: 1

balkaran singh
balkaran singh

Reputation: 2786

dispatch_async(dispatch_get_global_queue(0,0), ^{
    NSData * data = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString:[dictdetails objectForKey:@"profile_pic"]]];
    if ( data == nil )
        return;
    dispatch_async(dispatch_get_main_queue(), ^{

        cell.image = [UIImage imageWithData: data];
    });

});

plz use this code your ui will not get stuck if you use dispatch_async

Upvotes: 1

Related Questions