Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-05-2011, 04:15 AM   #1 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 23
Littlened is on a distinguished road
Default Can't seem to show an image in a cell

Can anyone point out where I might be going wrong?

Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    NSString *cellTitle = [[NSString alloc] initWithFormat:@"%@ %@",[[[self products] objectAtIndex:indexPath.row] brand],[[[self products] objectAtIndex:indexPath.row] model]];
    
    cell.textLabel.text = cellTitle;
    cell.detailTextLabel.text = [[[self products] objectAtIndex:indexPath.row] name];
    
    [cellTitle release];
    
    // Image
    NSString *cellImage = [[NSString alloc] initWithString:[[[self products] objectAtIndex:indexPath.row] imagePath]];
    NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: cellImage]];
    [[cell imageView] initWithImage:[UIImage imageWithData: imageData]];
    
    [imageData release];
    [cellImage release];
    
    return cell;
}
Littlened is offline   Reply With Quote
Old 11-05-2011, 04:24 AM   #2 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 23
Littlened is on a distinguished road
Default

I think I've solved it.

There wasn't a problem with the code, it was the image file names coming back from the server had spaces in them.
Littlened is offline   Reply With Quote
Old 11-05-2011, 04:53 AM   #3 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 23
Littlened is on a distinguished road
Default

Actually although that solved initial problem, I now seem to have another one. The images being loaded over the web were pretty large, so I've changed the image URL so that the image is resized by the server on the fly (much quicker).

So now the URL for an image might be
Code:
http://www.mydomain.com/resources/admin/phpthumb/public/uploads/products/images/853_rsg%200357%20Full%20Face%20400101.jpg&w=50&q=90&far=l
The problem is, when I do this my table view is empty and doesn't show any products.

I'm wondering if this URL is breaking the XML that gets returned by the server?

or is the problem something else?

Code:
// Image
    NSString *cellImage = [[NSString alloc] initWithString:[[[self products] objectAtIndex:indexPath.row] imagePath]];
    NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: cellImage]];
    [[cell imageView] initWithImage:[UIImage imageWithData: imageData]];
Littlened is offline   Reply With Quote
Old 11-05-2011, 05:55 AM   #4 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 23
Littlened is on a distinguished road
Default

Looks like it was the URL breaking the XML.

I returned an encoded URL, then created a method in my class to decode the URL;

Code:
-(NSString*) decodeURL:(NSString*)str {
    str = [str stringByReplacingOccurrencesOfString:@"%3A" withString:@":"];
    str = [str stringByReplacingOccurrencesOfString:@"%2F" withString:@"/"]; 
    str = [str stringByReplacingOccurrencesOfString:@"%3D" withString:@"="];
    str = [str stringByReplacingOccurrencesOfString:@"%3F" withString:@"?"];
    str = [str stringByReplacingOccurrencesOfString:@"%26" withString:@"&"];
    str = [str stringByReplacingOccurrencesOfString:@"%2520" withString:@"%20"];
    
    return str;
}
Littlened is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 413
17 members and 396 guests
7twenty7, Alex-alex, Apptronics RBC, baja_yu, dre, FrankWeller, gwelmarten, ipodphone, jeroenkeij, jleannex55, matador1978, n00b, pbart, reficul, Retouchable, Sami Gh, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,125
Posts: 402,910
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:19 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0