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 08-10-2010, 06:18 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 105
vamsi.ac is on a distinguished road
Default displaying images in rss as tableview cell image

i am left with only final task in my rss parser project.

my rss news has image in each view. but i am not able to display them as my table view cell image. please help me regarding this.

download my source code in here.
RssFun.zip
vamsi.ac is offline   Reply With Quote
Old 08-10-2010, 08:04 AM   #2 (permalink)
Registered Member
 
Ice_2k's Avatar
 
Join Date: Apr 2010
Location: Bucharest, Romania
Posts: 148
Ice_2k is on a distinguished road
Default

create a custom UITableViewCell and do whatever you want inside it (like adding an image view)
Ice_2k is offline   Reply With Quote
Old 08-10-2010, 08:14 AM   #3 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 105
vamsi.ac is on a distinguished road
Default

Quote:
Originally Posted by vamsi.ac View Post
i am left with only final task in my rss parser project.

my rss news has image in each view. but i am not able to display them as my table view cell image. please help me regarding this.

download my source code in here.
RssFun.zip
Quote:
Originally Posted by Ice_2k View Post
create a custom UITableViewCell and do whatever you want inside it (like adding an image view)
i am using these methods to display image in cell, but my table view scroll speeed reduced drastically,,,

Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
	UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"rssItemCell"];
	if(nil == cell){
		cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"rssItemCell"]autorelease];
	}
	cell = [self getCellContentView:@"rssItemCell"];
	UIImageView *tblimg=(UIImageView *)[cell viewWithTag:1];
	tblimg.tag=indexPath.row;
	
	NSString * mediaUrl = [[[[self rssParser]rssItems]objectAtIndex:indexPath.row]mediaUrl];
	if(nil != mediaUrl){
		NSData* imageData;
		[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
		@try {
			imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:mediaUrl]];
		}
		@catch (NSException * e) {
			//Some error while downloading data
		}
		@finally {
			UIImage * imageFromImageData = [[UIImage alloc] initWithData:imageData];
			[tblimg setImage:imageFromImageData];
			[imageData release];
			[imageFromImageData release];
		}
		[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
	}else{
		tblimg.image=[UIImage imageNamed:@"unknown.jpg"];
	}
	
	UILabel *titlelbl=[[UILabel alloc] initWithFrame:CGRectMake(90, 0, 250, 20)];
	UILabel *titledes=[[UILabel alloc] initWithFrame:CGRectMake(90, 30, 200, 40)];
	titlelbl.text=[[[[self rssParser]rssItems]objectAtIndex:indexPath.row]title];
	titledes.text= [[[[self rssParser]rssItems]objectAtIndex:indexPath.row]description];
	
	[cell.contentView addSubview:titlelbl];
	[cell.contentView addSubview:titledes];
	
	//cell.textLabel.text = [[[[self rssParser]rssItems]objectAtIndex:indexPath.row]title];
	//cell.detailTextLabel.text = [[[[self rssParser]rssItems]objectAtIndex:indexPath.row]description];
	

	
	cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
	return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	

	[[self appDelegate] setCurrentlySelectedBlogItem:[[[self rssParser]rssItems]objectAtIndex:indexPath.row]];
	[self.appDelegate loadNewsDetails];
	NSLog(@"vam");
	
	
	[tableView deselectRowAtIndexPath:indexPath animated:YES];

Code:

-(UITableViewCell *) getCellContentView:(NSString *)cellIdentifier 
{
	CGRect CellFrame = CGRectMake(0, 0, 300, 200);
	
	UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CellFrame reuseIdentifier:cellIdentifier] autorelease];
	cell.backgroundColor=[UIColor whiteColor];
    UIImageView *hello=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 80, 80)];
	hello.tag = 1;
	[cell.contentView addSubview:hello];
	[hello release];
	return cell;
}
how can i solve this
vamsi.ac is offline   Reply With Quote
Old 08-10-2010, 08:19 AM   #4 (permalink)
Registered Member
 
Ice_2k's Avatar
 
Join Date: Apr 2010
Location: Bucharest, Romania
Posts: 148
Ice_2k is on a distinguished road
Default

That's because you're loading the image each time the system requires a cell. When you're scrolling, the system loads each image over and over again (and actually downloading it over and over again if I'm reading your code correctly). What I used to get around this issue was to cache all table view cells in an array and when the system requires it, I just return it, no initialization needed. Depending on how much data you're using, you might need to think about treating memory warnings and clearing the cache.
Ice_2k is offline   Reply With Quote
Old 08-10-2010, 08:20 AM   #5 (permalink)
iphone developer
 
sivaram's Avatar
 
Join Date: Jun 2010
Location: Chennai
Age: 24
Posts: 32
sivaram is on a distinguished road
Send a message via Skype™ to sivaram
Default

Use this code,
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
	UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"rssItemCell"];
	if(nil == cell){
		cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"rssItemCell"]autorelease];
	}
	cell = [self getCellContentView:@"rssItemCell"];
	UIImageView *tblimg=(UIImageView *)[cell viewWithTag:1];
	tblimg.tag=indexPath.row;
	
	NSString * mediaUrl = [[[[self rssParser]rssItems]objectAtIndex:indexPath.row]mediaUrl];
	if(nil != mediaUrl){
		NSData* imageData;
		@try {
			imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:mediaUrl]];
		}
		@catch (NSException * e) {
			//Some error while downloading data
		}
		@finally {
			UIImage * imageFromImageData = [[UIImage alloc] initWithData:imageData];
			[tblimg setImage:imageFromImageData];
			[imageData release];
			[imageFromImageData release];
		}
	}else{
		tblimg.image=[UIImage imageNamed:@"unknown.jpg"];
	}
	
	UILabel *titlelbl=[[UILabel alloc] initWithFrame:CGRectMake(90, 0, 250, 20)];
	UILabel *titledes=[[UILabel alloc] initWithFrame:CGRectMake(90, 30, 200, 40)];
	titlelbl.text=[[[[self rssParser]rssItems]objectAtIndex:indexPath.row]title];
	titledes.text= [[[[self rssParser]rssItems]objectAtIndex:indexPath.row]description];
	
	[cell.contentView addSubview:titlelbl];
	[cell.contentView addSubview:titledes];
	


	
	cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
	return cell;
}
sivaram is offline   Reply With Quote
Old 08-10-2010, 08:34 AM   #6 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 105
vamsi.ac is on a distinguished road
Default

sivakumar, this is the same code u ve sent me before/?
vamsi.ac 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: 331
9 members and 322 guests
flamingliquid, ilmman, iram91419, linkmx, nadav@webtview.com, Objective Zero, Paul Slocum, stanny, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,656
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, iram91419
Powered by vBadvanced CMPS v3.1.0

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