Memory Leak related to setImage - ios

I have a memory leak which crashes the app. When i comment line above, i don't have any memory leak.
myCell.image1.image = image;
myCell is a custom UICollectionViewCell and created as:
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CustomCollectionCell *myCell = [collectionView dequeueReusableCellWithReuseIdentifier:#"project" forIndexPath:indexPath];
NSData *imageData = [NSData dataWithContentsOfFile:_images[row] options:0 error:NULL];
UIImage *image = [UIImage imageWithData:imageData];
myCell.image1.image = image;
return myCell;
}
The image is about 8 MB and there are 7 images. When I open the view controller for the forth time, the app crashes (8x7x4 > 200 MB) ;)
CustomCollectionCell.h
#import <UIKit/UIKit.h>
#import "CellButton.h"
#interface CustomCollectionCell : UICollectionViewCell
#property (strong, nonatomic) IBOutlet UILabel *titlePro;
#property (strong, nonatomic) IBOutlet UILabel *datePro;
#property (strong, nonatomic) IBOutlet UIImageView *image1;
#property (strong, nonatomic) IBOutlet CellButton * button;
#end
CustomCollectionCell.m
#import "CustomCollectionCell.h"
#import "UIView+Themes.h"
#implementation CustomCollectionCell
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
#end
I profiled and Live Bytes get higher than 200 MB, and the app crashes without errors. When i comment the myCell.image1.image = image;. The app doesn't crash.
I'm using ARC.
Do you have any ideas?

The view controller that contains CustomCollectionCell had a modal segue and i never called the line below.
[self dismissViewControllerAnimated:YES completion:nil];
That was why my images were not released.

Related

UICollectionView crashes when scrolling to the bottom

I have a UICollectionView that instantiates a bunch of images in a Flow Layout. The problem I have is when I scroll to the bottom of the view the app crashes and gives the following error: "*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[StickerPickerViewCell setImage:]: unrecognized selector sent to instance 0x101bdf470'". This seems odd to me because I don't know why it would be trying to add more images when you are at the bottom. Here is the code I have:
#import <UIKit/UIKit.h>
#interface StickerPickerViewCell : UICollectionViewCell
#property (weak, nonatomic) IBOutlet UILabel *testText;
#property (weak, nonatomic) IBOutlet UIImageView *stickerImage;
//- (void)setStickerImage:(StickerImage *)sticker;
#end
#import <Foundation/Foundation.h>
#import "StickerPickerViewCell.h"
#implementation StickerPickerViewCell
/*
- (void)setStickerImage:(StickerImage *)sticker{
{
self.stickerImage.image = [UIImage imageNamed:sticker.stickerImage];
}
*/
#end
#import <UIKit/UIKit.h>
#import "PhotoEditViewController.h"
#interface StickerPickerViewController : UIViewController <UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
//method declarations
- (void)viewDidLoad;
#property (weak, nonatomic) id<StickerPickerDelegate> pickerDelegate;
#property (weak, nonatomic) IBOutlet UICollectionView *stickerView;// sticker picker collection view
#property (nonatomic, strong) IBOutlet UICollectionViewFlowLayout *flowLayout;
#end
#import <Foundation/Foundation.h>
#import "StickerPickerViewController.h"
#import "StickerPickerViewCell.h"
#implementation StickerPickerViewController
//holds all the locations to the stickers we want to appear
- (void)viewDidLoad {
[super viewDidLoad];
[self.stickerView setBackgroundColor:[UIColor whiteColor]];
//flowlayout is how the cells organize around one another in the collectionview
self.flowLayout = [[UICollectionViewFlowLayout alloc] init];
[self.flowLayout setItemSize:CGSizeMake(40, 40)];
[self.flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
self.flowLayout.minimumInteritemSpacing = 0.0f;
[self.stickerView setCollectionViewLayout:self.flowLayout];
self.stickerView.bounces = YES;
[self.stickerView setShowsHorizontalScrollIndicator:NO];
[self.stickerView setShowsVerticalScrollIndicator:YES];
}
-(void)viewDidAppear:(BOOL)animated{
}
//////////////////////////////////////////////////COLLECTION VIEW METHODS ///////////////////////////////////////////////////////////////////
//number of cells to produce
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
//return list of sticker's size
//printf("i: %lu", (unsigned long)[stickerList count]);
StickerManager* stickerManager = [self.pickerDelegate stickerManagerForStickers];
return stickerManager.stickers.count;
}
// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
StickerManager* stickerManager = [self.pickerDelegate stickerManagerForStickers];
Sticker* sticker = stickerManager.stickers[indexPath.row];
//create cell
StickerPickerViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"stickerPickerViewCell" forIndexPath:indexPath];
//set cell image to image associated with the path in the array
cell.stickerImage.image = sticker.preview;
cell.stickerImage = (UIImageView *)[cell viewWithTag:100];
return cell;
}
//cell size
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(75, 75);
}
//number of cell sections
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
//get the selected image as String
Sticker* selectedSticker = [self.pickerDelegate stickerManagerForStickers].stickers[indexPath.row];
[self dismissViewControllerAnimated:YES completion:nil];
[self.pickerDelegate didSelectSticker:selectedSticker];
//dismiss popover
[self dismissViewControllerAnimated:true completion:nil];
}
#end
What could be causing this crash?

UIImage not being received via first view controller

Hi there i currently have just "think i have cracked sending content through a prepare for segue" but the problem is that my images are not showing up in the second view controller. As I'm kind of new to this i would like to know if there is something that i am missing because no matter what i can't seem to get the image of my first view controller to show in my second view controller.
GroupsViewController.h
#import <UIKit/UIKit.h>
#interface GroupsViewController : UIViewController<UICollectionViewDataSource, UICollectionViewDelegate>
#property (weak, nonatomic) IBOutlet UICollectionView *GroupsCollectionView;
- (IBAction)cellToggleAction:(id)sender;
#end
GroupsViewController.m
#import "GroupsViewController.h"
#import "GroupsHomeViewController.h"
#import "CustomCell.h"
#interface GroupsViewController ()
{
NSArray *arrayOfImages;
NSArray *arrayOfDescriptions;
}
#end
#implementation GroupsViewController
{
NSString *reuseIdentifier;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[[self GroupsCollectionView]setDataSource:self];
[[self GroupsCollectionView]setDelegate:self];
reuseIdentifier= #"SmallIcon"; //set inital value of reuse identifier
arrayOfImages = [[NSArray alloc]initWithObjects:#"a.png", nil];
arrayOfDescriptions = [[NSArray alloc]initWithObjects:#"A", nil];
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return [arrayOfDescriptions count];
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
[[cell IconImage]setImage:[UIImage imageNamed:[arrayOfImages objectAtIndex:indexPath.item]]];
[[cell IconLabel]setText:[arrayOfDescriptions objectAtIndex:indexPath.item]];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:#"GroupsHomeSegue" sender:indexPath];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"GroupsHomeSegue"])
{
NSIndexPath* indexPath = [[self.GroupsCollectionView indexPathsForSelectedItems]firstObject];
if(indexPath !=nil)
{
//NSString *selectedDescription = arrayOfDescriptions[indexPath.item]; //collects description from cell
NSString *selectedImage = arrayOfImages [indexPath.item]; //collects image from cell
GroupsHomeViewController *groupsHomeViewController = segue.destinationViewController;
groupsHomeViewController.logoImage = [UIImage imageNamed: selectedImage];
//groupsHomeViewController.groupLabel = [:selectedDescription];
}
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
//Dispose of any resources that can be recreated.
}
#end
GroupsHomeViewController.h
#import <UIKit/UIKit.h>
#interface GroupsHomeViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>
#property (strong, nonatomic) IBOutlet UIImage *logoImage;
#property (strong, nonatomic) IBOutlet UILabel *groupLabel;
#end
GroupsHomeViewController.m
#import "GroupsHomeViewController.h"
#interface GroupsHomeViewController ()
#end
#implementation GroupsHomeViewController
-(void)viewDidLoad{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Thank You in advance for your kind help.
Lee Sugden,
Passing an image is not enough :) If you want it to show on your screen you should load it in an ImageView isn't it :)
Now either create UIImageView programmatically or add a imageView in your story board draw an IBOutlet and set the image as
self.yourImageView.image = self.logoImage;
else create an UIImageView programmatically as,
UIImageView *yourImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,self.logoImage.size.width,self.logoImage.size.height)];
yourImageView.image = self.logoImage;
[self.view addSubview:yourImageView];
The issue lies in your GroupsHomeViewController. You need a UIImageView as your IBOutlet rather than a UIImage, then you need to set the image property on the image view to your desired image. To do this, you need to update your GroupsHomeViewController.h file like so:
#interface GroupsHomeViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>
#property (strong, nonatomic) IBOutlet UIImageView *logoImageView;
#property (strong, nonatomic) UIImage *logoImage;
#property (strong, nonatomic) IBOutlet UILabel *groupLabel;
#end
And then in your GroupsHomeViewController.m, set your image view's image in the viewWillAppear:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.logoImageView.image = self.logoImage;
}
Now, when you set logoImage in your segue, the image view will load the image just before the view appears.
This is assuming that you have the image view already on your storyboard with the outlet correctly connected.
I think the guys above may have solved this with the advice to set the image to whatever image view is holding it. But if that still hasn't solved it, with prepareForSegue, I've had problems due to iOS voodoo where the variable isn't set. So to be sure, override the setter in your GroupsHomeViewController.m to make sure the object is properly assigned to your image property.
- (void)setLogoImage:(UIImage *)logoImage
{
_logoImage = logoImage;
}

UICollectionView with images : Memory increases up to 1.75 GB

My iPhone App displays a CollectionView with about 100 Images separated by Headers. The Images have a size from about 200Kb. In the debug navigator the memory increases up to 1.75 GB while scrolling the CollectionView. It still runs smooth, but there must be a reason for that.
#property (strong, nonatomic) NSArray *picturesMoon;
#property (strong, nonatomic) NSArray *picturesEarth;
#property (strong, nonatomic) NSArray *picturesVenus;
#property (strong, nonatomic) NSArray *picturesMars;
#property (strong, nonatomic) NSDictionary *plistDict;
#property (strong, nonatomic) NSString *picName;
#property (strong, nonatomic) MyCustomCell *myCell;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"Milkyway.png"]];
self.plistDict=[[NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"Praxis" ofType:#"plist"]] objectForKey:#"Universe"];
// Pictures Moon
picturesMoon = [self.plistDict objectForKey:#"Moon"];
// Pictures Earth
picturesEarth = [self.plistDict objectForKey:#"Earth"];
// Pictures Mars
picturesMars = [self.plistDict objectForKey:#"Mars"];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
self.myCell = [collectionView dequeueReusableCellWithReuseIdentifier:#"collectionCell" forIndexPath:indexPath];
// Sections
switch (indexPath.section) {
case 0:
self.myCell.imageInCell.image = [UIImage imageNamed:[picturesMoon objectAtIndex:indexPath.item]];
break;
case 1:
self.myCell.imageInCell.image = [UIImage imageNamed:[picturesEarth objectAtIndex:indexPath.item]];
break;
case 2:
self.myCell.imageInCell.image = [UIImage imageNamed:[picturesMars objectAtIndex:indexPath.item]];
break;
case 3:
self.myCell.imageInCell.image = [UIImage imageNamed:[picturesVenus objectAtIndex:indexPath.item]];
break;
default:
break;
}
return self.myCell
}
- (UICollectionReusableView *) collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
// Header for Sections
HeaderCollectionView *myHeaderView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:#"Header" forIndexPath:indexPath];
switch (indexPath.section) {
case 0:
myHeaderView.labelOutlet.text = #"Moon";
break;
case 1:
myHeaderView.labelOutlet.text = #"Earth";
break;
...
...
default:
break
}
return myHeaderView;
}
MyCustomCell is just a few line of Code
#import "MyCustomCell.h"
#implementation MyCustomCell
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
and the Header for MyCustomCell just
#import <UIKit/UIKit.h>
#interface MyCustomCell : UICollectionViewCell
#property (strong, nonatomic) IBOutlet UIImageView *imageInCell;
#end
[UIImage imageNamed:] caches the images. The large memory footprint isn't necessarily a problem, as the cache will be automatically purged if memory is too low. That said, if you want to avoid caching, you can use another method to load the images, for example:
NSString *imageName = [picturesMars objectAtIndex:indexPath.item];
NSString *imagePath = [[NSBundle mainBundle] pathForResource:imageName ofType:#"PNG"]; // PNG, or whatever file tile you are actually using
UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
self.myCell.imageInCell.image = image;

iOS UICollectionView memory leak

I've created UICollectionView through storyboard.
My cell is custom cell class that have 3 buttons with images.
My images are available as part of class GalleryItemInfo. I have an array of those objects
[GalleryDataProvider sharedInstance].itemInfo
There is code for cellForItemAtIndexPath (in one cell there are three buttons for three items in array):
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CollectionViewCellPreviewTriple *cell;
if (indexPath.row % 2 == 0 && !is_iPhone) {
cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"cellOrangeRed" forIndexPath:indexPath];
if (is_Fingerprint_Version) {
cell.imageViewRope.image = [UIImage imageNamed:#"image-rope-1.png"];
}
} else {
cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"cellGreenBlue" forIndexPath:indexPath];
if (is_Fingerprint_Version) {
cell.imageViewRope.image = [UIImage imageNamed:#"image-rope-2.png"];
}
}
cell.previewCellDelegate = self;
cell.tag = indexPath.row;
NSInteger leftPreviedId = [cell firstPreviewId];
self.leftPreviewedID = leftPreviedId;
UIImage *image1 = ((GalleryItemInfo *)[[GalleryDataProvider sharedInstance].itemInfo objectAtIndex:leftPreviedId]).slotPreviewImage;
UIImage *image2;
UIImage *image3;
if (leftPreviedId + 1 < [[GalleryDataProvider sharedInstance].itemInfo count])
image2 = ((GalleryItemInfo *)[[GalleryDataProvider sharedInstance].itemInfo objectAtIndex:leftPreviedId + 1]).slotPreviewImage;
if (leftPreviedId + 2 < [[GalleryDataProvider sharedInstance].itemInfo count])
image3 = ((GalleryItemInfo *)[[GalleryDataProvider sharedInstance].itemInfo objectAtIndex:leftPreviedId + 2]).slotPreviewImage;
[cell setupWithImage1:image1 image2:image2 image3:image3];
if (self.isEditModeEnabled) {
[cell showRemoveButtons];
} else {
[cell hideRemoveButtons];
}
return cell;
}
Trouble: when I scroll my collection memory usage increases every swipe from right to left on about 1 megabyte.
Why memory is not released?
Update:
CollectionViewCellPreviewTriple code (created through storyboard):
#import <UIKit/UIKit.h>
#protocol UICollectionViewPreviewCellDelegate;
#interface CollectionViewCellPreviewTriple : UICollectionViewCell
#property (weak, nonatomic) IBOutlet UIButton *buttonSlot1;
#property (weak, nonatomic) IBOutlet UIButton *buttonSlot2;
#property (weak, nonatomic) IBOutlet UIButton *buttonSlot3;
#property (weak, nonatomic) IBOutlet UIButton *buttonRemove1;
#property (weak, nonatomic) IBOutlet UIButton *buttonRemove2;
#property (weak, nonatomic) IBOutlet UIButton *buttonRemove3;
#property (weak, nonatomic) IBOutlet UIImageView *imageViewRope;
#property (nonatomic, weak) id<UICollectionViewPreviewCellDelegate> previewCellDelegate;
- (void)setupWithImage1:(UIImage *)image1 image2:(UIImage *)image2 image3:(UIImage *)image3;
- (void)showRemoveButtons;
- (void)hideRemoveButtons;
- (NSInteger)firstPreviewId;
#end
#protocol UICollectionViewPreviewCellDelegate
- (void)collectionViewPreviewCell:(CollectionViewCellPreviewTriple *)collectionViewCell didSelectSubitemWithIndex:(NSInteger)subitemIndex;
- (void)collectionViewPreviewCell:(CollectionViewCellPreviewTriple *)collectionViewCell didEditModeRequestWithStatus:(BOOL)status;
- (void)collectionViewPreviewCell:(CollectionViewCellPreviewTriple *)collectionViewCell didRemoveRequestWithIndex:(NSInteger)subitemIndex;
- (void)slotButtonRequestsShadow:(UIButton *)slotButton;
#end
Update:
- (void)setupWithImage1:(UIImage *)image1 image2:(UIImage *)image2 image3:(UIImage *)image3
{
[self.buttonSlot1 setBackgroundImage:image1 forState:UIControlStateNormal];
[self.buttonSlot1 setBackgroundImage:image1 forState:UIControlStateHighlighted];
//if (image2) {
[self.buttonSlot2 setBackgroundImage:image2 forState:UIControlStateNormal];
[self.buttonSlot2 setBackgroundImage:image2 forState:UIControlStateHighlighted];
[self.buttonSlot2 setHidden:(image2 == nil)];
//}
//if (image3) {
[self.buttonSlot3 setBackgroundImage:image3 forState:UIControlStateNormal];
[self.buttonSlot3 setBackgroundImage:image3 forState:UIControlStateHighlighted];
[self.buttonSlot3 setHidden:(image3 == nil)];
//}
}
Profiling
link for screen
This may be related to the issue that many people have been suffering with where the cell's are not reused.
To test this, you should override the method prepareForReuse and in it write a very simple log:
NSLog(#"%# is being called as expected.", NSStringFromSelector(_cmd));
You should then run your app, scroll the collection view, and check the console to see if this log appears.
If this log does not appear, you may want to check this answer for help as to how to proceed. In my app cells are not reused in the simulator, but are reused on devices. It's odd.

Changing Image on selected state of UITablView cell

I have a created a custom cell and added one label and Image, I have 4 rows in my table each row has a different image and each row opens a different view controller, so, now what I need is on click of a particular row I want the image to change to do that I tried this, but its not working, so please help me out.
if(indexPath.row == 0)
{
if(cell.selected == true)
{
UIImage *cellImage = [UIImage imageNamed:#"abc.png"];
cell.icon.image = cellImage;
}
else
{
UIImage *cellImage = [UIImage imageNamed:#"abc.png"];
cell.icon.image = cellImage;
}
}
Regards
Ranjit
Try to do following when creating your cell or in tableView:willDisplayCell:forRowAtIndexPath: method:
cell.imageView.image = [UIImage imageNamed:#"abc.png"];
cell.imageView.highlightedImage = [UIImage imageNamed:#"abc.png"];
It will work for your icon property too if it is UIImageView
First create a property in your custom cell for uiImageview and synthesize it..
and the in didSelectRowAtIndexPath delegate method of UITabeView access the property and change the image something like :-
yourCell.yourImageView.image=[UIImage imageNamed:#"yourImage"]
For Sample I am giving my Code :-
#import <UIKit/UIKit.h>
#interface CustomizedCellProductDetails : UITableViewCell {
UILabel *sNO;
UILabel *abcWine;
UILabel *redWine;
UILabel *two;
UILabel *hundred;
UILabel *fourTwo;
UILabel *twoOne;
UIImageView *imgView;
UILabel *itemNo;
UILabel *itemName;
UILabel *itemDesc;
UILabel *department;
UILabel *qtyAvailable;
UIButton *check;
}
#property (nonatomic , retain) UILabel *sNO;
#property (nonatomic , retain) UILabel *abcWine;
#property (nonatomic , retain) UILabel *redWine;
#property (nonatomic , retain) UILabel *two;
#property (nonatomic , retain) UILabel *hundred;
#property (nonatomic , retain) UILabel *fourTwo;
#property (nonatomic , retain) UILabel *twoOne;
#property (nonatomic , retain) UIImageView *imgView;
#property (nonatomic , retain) UILabel *itemNo;
#property (nonatomic , retain) UILabel *itemName;
#property (nonatomic , retain) UILabel *itemDesc;
#property (nonatomic , retain) UILabel *department;
#property (nonatomic , retain) UILabel *qtyAvailable;
#property (nonatomic , retain) UIButton *check;
-(void) clicked;
#end
.m file synthesize it:-
#import "CustomizedCellProductDetails.h"
#implementation CustomizedCellProductDetails
#synthesize sNO,abcWine,redWine,two,hundred,fourTwo,twoOne,imgView,itemNo,itemName,itemDesc,department,qtyAvailable,check;
in tableview delegate :-
#pragma mark -
#pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:#"<#Nib name#>" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
*/
CustomizedCellProductDetails * cell = (CustomizedCellProductDetails )[tableView cellForRowAtIndexPath:indexPath];
[cell.imgView setImage:[UIImage imageNamed:#"wine.png"]];
}
Try to do following when creating your cell ...
In Implementation Block...
#implementation ABC
{
NSMutableArray *imageArray;
NSMutableArray *imageSelectedArray;
}
Do this In the below method
(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
[cell.imageView setImage:[UIImage imageNamed:[imageArray objectAtIndex:indexPath.row]]];
[cell.imageView setHighlightedImage:[UIImage imageNamed:[imageSelectedArray objectAtIndex:indexPath.row]]];
}

Resources