Вы можете переместить часть создания внутрь предложения if
, которое создает новую ячейку.
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellID] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
CGRect labelCourseFrame = CGRectMake(10, 10, 290, 25);
labelCourse = [[UILabel alloc] initWithFrame:labelCourseFrame];
labelCourse.font = [UIFont systemFontOfSize:14.0];
labelCourse.font = [UIFont boldSystemFontOfSize:18];
[cell.contentView addSubview:labelCourse];
CGRect labelPlaceFrame = CGRectMake(10, 35, 290, 25);
labelPlace = [[UILabel alloc] initWithFrame:labelPlaceFrame];
labelPlace.font = [UIFont systemFontOfSize:12.0];
labelPlace.textColor = [UIColor darkGrayColor];
[cell.contentView addSubview:labelPlace];
labelCourse.tag = 50;
labelPlace.text = 51;
[labelCourse release];
[labelPlace release];
}
Как вы видите, я прикрепил tag
s к представлениям, чтобы я мог получить метки при повторном использовании ячеек. Теперь получите этикетки,
UILabel * labelCourse = [cell viewWithTag:50];
UILabel * labelPlace = [cell viewWithTag:51];
и установите их,
labelCourse.text = course.name;
labelPlace.text = course.location;