【发布时间】:2013-08-28 04:02:24
【问题描述】:
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;
}
图片如下:
【问题讨论】:
-
您每次都在向您的单元格添加一个新标签。请尝试在
.detailLabel属性中设置您的文本。 -
我正在为 iPhone 使用 FPPopOver,它不允许 .detailLabel。我必须使用标签。
标签: ios objective-c uitableview cell-formatting