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 10-24-2010, 03:43 PM   #1 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 9
dciso is on a distinguished road
Default UITableView slow scrolling because of images

Hey, I just need some advice. Ive nearly completed my first iphone app and ive just got one problem to sort before its done. At the minute ive got a UITableView with images in each cell that are loaded from a server (see a screenshot here). On wifi it will scroll fine but on 3G it won’t scroll smoothly because it waits until the image is loaded before continuing to scroll. Ive seen in most apps (ebay for example) that it will still scroll even if the images havnt loaded it yet. I was wondering how to achieve that effect? Cheers, Jason.
dciso is offline   Reply With Quote
Old 10-25-2010, 04:15 AM   #2 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 9
dciso is on a distinguished road
Default

Ive included my code below:
Code:
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
	UITableViewCell *cell =
	[tableView dequeueReusableCellWithIdentifier:@"cell"];
	
	// create a cell
	if ( cell == nil)
	{
		cell = [[UITableViewCell alloc]
				initWithStyle:UITableViewCellStyleSubtitle
				reuseIdentifier:@"cell"];
	}
	
	// fill it with contents
	NSDictionary *dict = [NSDictionary dictionaryWithDictionary: [manuArray objectAtIndex:indexPath.row]]; 
	cell.textLabel.text = [dict objectForKey:@"manufacturer_name"];
	cell.textLabel.font = [UIFont systemFontOfSize:14.0];
	cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
	
	NSString *noProducts = [NSString stringWithFormat:@"%@",[dict objectForKey:@"no_products_found"]];
	
	if([noProducts isEqualToString:@"1"]==TRUE){
		cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ item found", noProducts];
	} else {
		cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ items found", noProducts];
	}
	
	
	
	NSData *imgData;

	
	if([[dict objectForKey:@"image_url"] isEqualToString:@"none"]==FALSE) {
		NSString *urlString = [NSString stringWithFormat:@"http://172.16.7.80/psyche%@",[dict objectForKey:@"image_url"]];
		NSURL *imgUrl = [NSURL URLWithString: urlString];
		imgData = [NSData dataWithContentsOfURL:imgUrl]; 
	} else {
		NSString *imagefile = [[NSBundle mainBundle] 
							   pathForResource:@"no_image" ofType:@"png"];
		imgData = [NSData dataWithContentsOfFile: imagefile];
	}
	
	//set the image on the table cell
	cell.imageView.image =  [UIImage imageWithData: imgData]; 
	return cell;
}
dciso is offline   Reply With Quote
Old 10-25-2010, 05:08 AM   #3 (permalink)
Registered Member
 
Join Date: Sep 2008
Location: London, UK
Posts: 1,050
wuf810 is on a distinguished road
Default

Quote:
Originally Posted by dciso View Post
Hey, I just need some advice. Ive nearly completed my first iphone app and ive just got one problem to sort before its done. At the minute ive got a UITableView with images in each cell that are loaded from a server (see a screenshot here). On wifi it will scroll fine but on 3G it won’t scroll smoothly because it waits until the image is loaded before continuing to scroll. Ive seen in most apps (ebay for example) that it will still scroll even if the images havnt loaded it yet. I was wondering how to achieve that effect? Cheers, Jason.
There are many example apps (including source) demoing this. In fact I think Apple even have a demo.

Much easier for you to check out the examples directly. It's not difficult so sure you'll get it implemented quickly.

M.
wuf810 is offline   Reply With Quote
Old 10-25-2010, 05:54 AM   #4 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 9
dciso is on a distinguished road
Default

Cheers for your reply, got it sorted. I'd recommend using this simple extension to UIImageView.
dciso is offline   Reply With Quote
Old 10-25-2010, 05:59 AM   #5 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 108
iphone_bharat is on a distinguished road
Default

-EDIT-
iphone_bharat is offline   Reply With Quote
Old 01-27-2012, 04:29 PM   #6 (permalink)
[[Brain alloc]init];
 
fhsjaagshs's Avatar
 
Join Date: Aug 2011
Location: New Jersey
Age: 15
Posts: 92
fhsjaagshs is on a distinguished road
Default

The ebay app threads the image-setting:

1. Create an NSDictionary for each cell, add an indexPath.row number and image name/url
2. When an image downloads, set the image using the NSDictionary. This action is most likely threaded.
fhsjaagshs is offline   Reply With Quote
Old 01-27-2012, 05:14 PM   #7 (permalink)
Registered Member
 
Join Date: Jan 2012
Posts: 75
ckgni is on a distinguished road
Default

Have a look at the LazyTableImages sample Xcode project provided by Apple.
You can download the sample project here:
LazyTableImages

It loads first the text and then the images and the scrolling is very smooth.
ckgni 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: 323
13 members and 310 guests
7twenty7, chiataytuday, condor304, Desert Diva, Domele, dre, dreamdash3, mottdog, oceanlablight, palme2elie, Paul Slocum, schmallegory
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,659
Threads: 94,118
Posts: 402,895
Top Poster: BrianSlick (7,990)
Welcome to our newest member, dreamdash3
Powered by vBadvanced CMPS v3.1.0

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