08-10-2010, 06:18 AM
#1 (permalink )
Registered Member
Join Date: Aug 2009
Posts: 105
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
08-10-2010, 08:04 AM
#2 (permalink )
Registered Member
Join Date: Apr 2010
Location: Bucharest, Romania
Posts: 148
create a custom UITableViewCell and do whatever you want inside it (like adding an image view)
08-10-2010, 08:14 AM
#3 (permalink )
Registered Member
Join Date: Aug 2009
Posts: 105
Quote:
Originally Posted by
vamsi.ac
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
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
08-10-2010, 08:19 AM
#4 (permalink )
Registered Member
Join Date: Apr 2010
Location: Bucharest, Romania
Posts: 148
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.
08-10-2010, 08:20 AM
#5 (permalink )
iphone developer
Join Date: Jun 2010
Location: Chennai
Age: 24
Posts: 32
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;
}
08-10-2010, 08:34 AM
#6 (permalink )
Registered Member
Join Date: Aug 2009
Posts: 105
sivakumar, this is the same code u ve sent me before/?
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» 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