2016-05-26 21 views
1

sind immer die 3 Fehler für diesenAnzeigen von Bildern von JSON URL in Tableview

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

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

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

unter meinem Code. Könnten Sie mir bitte helfen, dieses Thema zu lieben?

- (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; 
} 
+0

glaube ich matchesProfileArr Array null zu prüfen ist, ob seine Null oder nicht –

+0

, was diese Codezeile Sie Rückkehr [dictdetails objectForKey: @ „profile_pic“]; – Alok

+0

willst du Bild von URL anzeigen? –

Antwort

1

Sie senden eine Zeichenfolge an das Bild. Sie müssen Bild von der URL wie folgt laden:

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

EDIT: Dies ist synchrones Bild laden.

Ich möchte Sie Sie AFNetworking Verfahren zum Laden Bild von URL Benutzer vorschlagen:

[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]]]; 
    }); 
+1

synchrone net comms ... bad .... – trojanfoe

+1

Ja, ich stimme zu. Ich werde bearbeiten. – Stefan

+0

die Zeit, die ich kommentierte :) – Alok

1
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 diesen Code verwenden, um Ihre ui nicht stecken Wenn Sie dispatch_async verwenden

0

Nur eine Ergänzung zu den Antworten von @Stefan und @ balkaranSingh . Ich denke, Ihr @"age" Schlüssel hält NSNumber nicht NSString, aus diesem Grund konvertieren Sie es in Zeichenfolge.

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