开发者

UIITabelViewCell displaying incorrect images

Hi friends i am displaying image on table cell say table have 10 cell

but i am displaying images only on two cell

when i scroll table view this images come one by one on all cell

so what's i am doing wrong here.

static NSString* identifier = @"CellTypeLabel";

    // create custom cell
CustomizedTableCells* cell = nil;   
if (cell == nil)
    cell = [[[CustomizedTableCells alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];

    // cell accessory type
cell.accessoryType =  UITableViewCellAccessoryDisclosureIndicator;

cell.imageView.image = nil;

NyhtrAppDelegate *appDelegate = (NyhtrAppDelegate *)[[UIApplication sharedApplication] delegate];
NSXMLElement* node = [appDelegate.items objectAtIndex:indexPath.row];
NSLog(@"\n Output :: %@ :: ", [node XMLString])开发者_开发问答;

    // set the lable name for a cell
if(node != NULL)
{       
    int width = cell.contentView.bounds.size.width-50;
    if([[[node elementForName:@"pubDate"] stringValue]length] > 0)
        [cell setCellWithTitleAndSize:[[node elementForName:@"title"] stringValue] rect:CGRectMake(45, 0, width, 35) size: 17];
    else
        [cell setCellWithTitleAndSize:@"N/A" rect:CGRectMake(45, 0, width, 35) size: 17];       
}   

NSXMLElement* iconElement = [self getIconElementForThisDomain:[self getDomain:node]];

NSString* iconImageUrl = nil;
if (nil != iconElement)
    iconImageUrl = [[iconElement elementForName:@"retina-icon"]stringValue];
else
    iconImageUrl = @"http://nyhtr.se/icon/nyheter24.png";   

// cached images    
NSString* imageName = [[UICachedImageMgr defaultMgr] imageNameFromURLString:iconImageUrl];
UIImageProxy* imageProxy = [UICachedImageMgr imageWithName:imageName userInfo:self];

cell.imageView.image = imageProxy.image;     

return cell;    


check the following method and add images only to matching indexpath.row integer value

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    //check the indexPath
    if(indexPath.row==0 || indexPath.row==5){
    }
    else{
    //other stuff
    } 

}


If you use cell dequeuing, your dequeued cell could be one of those with the image in it.

So, if your cell was dequeued, you have to check if the image is there and remove it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜