UITableViewCell verwendet bewährte Methoden erneut
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"NotificationViewCell";
CardViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell==nil){
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CardViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
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];
Merchant *merchantList= [self.cardListArr objectAtIndex:indexPath.row];
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];
}
}
return cell;
}
Ich möchte den obigen Code verwenden, um UITableViewCell wiederzuverwenden. Ich weiß nicht, ob es richtig ist. Ich möchte einen Rat bekommen.Sie können meinen Code sehen, den ich benutze, wenn (cell == nil), ich möchte wissen, ich sollte schreiben, welcher Code wenn (cell! = nil) (if (cell == nil) sonst {ich sollte tun, was die Wiederverwendung von Zellen verbessern kann })
Wenn jede Zelle die gleichen Ansichten hat, aber eine andere Höhe hat, ist die Bildansicht manchmal 20 oder 40 und so weiter, wie man mit der Situation umgeht.