Better u need to subclass the tableview because, each time you are reusing the cell, but its subview are not, so just do like this
create a new file and name it as MyCustomCell
subclass of UITableViewCell
in MyCustomCell.h
file
MyCustomCell.h
#import <UIKit/UIKit.h>
@interface MyCustomCell : UITableViewCell
@property (nonatomic, retain) UIImage *logoOff;
@property (nonatomic, retain) UIImage *logoOn;
@property (nonatomic, retain) UIButton *logo;
@property (nonatomic, retain) UILabel *name;
@property (nonatomic, retain) UIImageView *divider;
@end
in MyCustomCell.m file
MyCustomCell.m
#import "MyCustomCell.h"
@implementation MyCustomCell
@synthesize logoOn;
@synthesize logoOff;
@synthesize logo;
@synthesize name;
@synthesize divider;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.logo = [UIButton buttonWithType:UIButtonTypeRoundedRect];
self.logo.userInteractionEnabled = NO;
self.logo.selected = FALSE;
self.name = [[UILabel alloc]initWithFrame:CGRectZero];
[self.name setFont:[UIFont fontWithName:@"CenturyGothic" size:14]];
self.name.numberOfLines = 2;
self.name.backgroundColor = [UIColor clearColor];
[self.name sizeToFit];
self.name.textColor = [UIColor whiteColor];
self.divider = [[UIImageView alloc]init];
[self.contentView addSubview:logo];
[self.contentView addSubview:name];
[self.contentView addSubview:divider];
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (void)layoutSubviews
{
[super layoutSubviews];
// set the frames for all subviews
[self.logo setBackgroundImage:self.logoOff forState:UIControlStateNormal];
[self.logo setBackgroundImage:self.logoOn forState:UIControlStateSelected];
[self.logo setBackgroundImage:self.logoOn forState:UIControlStateHighlighted];
self.logo.frame = CGRectMake(20, 5, self.logoOff.size.width/2, self.logoOff.size.height/2);
self.name.frame = CGRectMake(70,13, self.bounds.size.width-70, 20);
self.divider.frame = CGRectMake(0, 43, self.bounds.size.width ,2);
}
@end
and in the controller
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MyCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CELL"];
if(cell == nil)
{
cell = [[MyCustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CELL"];
}
cell.logoOff = [UIImage imageNamed:[logoimg objectAtIndex:indexPath.row*2]];
cell.logoOn = [UIImage imageNamed:[logoimg objectAtIndex:indexPath.row*2]];
cell.name.text = [logoname objectAtIndex:indexPath.row];
// cell.divider.image = [UIImage imageNamed:@"divider_line.png"]; //for test i commented
cell.divider.backgroundColor = [UIColor blackColor];
return cell;
}
Hope this helps u :)