- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @\"NotificationViewC
I usually separate the creation and configuration of the cell into two logical parts:
-(void)configureCell:(UITableViewCell*)cell;
function where I set up everything specific for a particular cell from the datasource (i.e. values of labels and imageView).Then in cellForRowAtIndexPath
:
-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"NotificationViewCell";
CardViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell==nil){
[self createCell:&cell];
}
Mercant* mercantList = [self.cardListArr objectAtIndex:indexPath.row];
[self configureCell:cell withMercant:mercantList];
return cell;
}
-(void)createCell:(CardViewCell**)cellPtr
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CardViewCell"
owner:self
options:nil];
*cellPtr = [nib objectAtIndex:0];
CardViewCell* cell = *cellPtr;
cell.contentView.backgroundColor=[UIColor clearColor];
[ModelClass addSublayer:cell.contentView];
cell.cellbg.layer.cornerRadius = 8;
cell.cellbg.layer.masksToBounds = YES;
cell.cellbg.layer.borderWidth = 1;
cell.cellbg.layer.borderColor = [[UIColor grayColor] CGColor];
cell.logoImage.layer.cornerRadius = 8;
cell.logoImage.layer.masksToBounds = YES;
cell.logoImage.layer.borderWidth = 1;
cell.logoImage.layer.borderColor = [[UIColor grayColor] CGColor];
}
-(void)configureCell:(CardViewCell*)cell withMercant:(Mercant*)mercantList
{
cell.nameLab.text=merchantList.name;
NSLog(@"merchantList.myloyalty.points=%@",merchantList.myloyalty.points);
// NSLog(@"memberNO=%@",merchantList.myloyalty.memberNO);
cell.integralLab.text=[NSString stringWithFormat:NSLocalizedString(@"points_dot", @"") ,[merchantList.myloyalty.points intValue]];
cell.cardNumberLab.text=[NSString stringWithFormat:@"%@%@",NSLocalizedString(@"ID", nil), merchantList.myloyalty.memberNO];
if(![ModelClass isBlankString:merchantList.introPic])
{
NSLog(@"merchantList.introPic=%@",merchantList.introPic);
[cell.logoImage setImageUrl:merchantList.introPic];
}
}