cellForRowAtIndexPath:
cell.textLabel.text 工作正常。
滚动后 UILabel 重叠。这是代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell==nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
// I have tried it by removing views and without. No difference.
NSArray *viewsToRemove = [self.tableView subviews];
for (UITableView *table in viewsToRemove)
{
[table removeFromSuperview];
}
}
NSManagedObject *managedObject = [newClass objectAtIndex:indexPath.row];
NSString *entityName= [[managedObject entity]name];
cell.textLabel.text = [NSString stringWithFormat:@"%@ %i", entityName, [indexPath row]];
cell.textLabel.font=[UIFont systemFontOfSize:14.0];
NSDate *date = [managedObject valueForKey:@"lastmoddate"];
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"EEE, MMM d, YYYY h:mm a"];
NSString *dateString = [formatter stringFromDate:date];
UILabel *lblDate = [[UILabel alloc] initWithFrame:CGRectMake(10, 30, 215, 10)];
lblDate.text = dateString;
lblDate.textColor = [UIColor grayColor];
lblDate.font = [UIFont systemFontOfSize:10.0];
[lblDate setBackgroundColor:[UIColor clearColor]];
[cell.contentView addSubview:lblDate];
return cell;
}
这是图像: