在我的应用程序中,我有一个 imageView 和一个 UILabel。对于 ImageView,我已经为它分配了异步图像,它工作正常,但是当我滚动表格时,第一行和最后一行的标签会重叠。
这是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
productObject=[appDelegate.productArray objectAtIndex:indexPath.row];
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UILabel *nameLabel;
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
}
else
{
AsyncImageView* oldImage = (AsyncImageView*)[cell.contentView viewWithTag:999];
[oldImage removeFromSuperview];
}
CGRect nameLabelRect = CGRectMake(70,80,150,15);
nameLabel = [[UILabel alloc] initWithFrame:nameLabelRect];
nameLabel.text = [NSString stringWithFormat:@"%@",productObject.productname];
nameLabel.textAlignment = UITextAlignmentCenter;
nameLabel.lineBreakMode = UILineBreakModeCharacterWrap;
nameLabel.font = [UIFont boldSystemFontOfSize:15];
nameLabel.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview: nameLabel];
}