Я собираюсь иметь ячейки с разными подпредставлениями в зависимости от выбранной категории. Я выбираю новую категорию, перезагружаю данные и т. Д., Но вместо того, чтобы отображать новую ячейку с другими подпредставлениями, при переключении между категориями эти представления накладываются друг на друга, как это исправить?
Вот мой код:
//cell for row at indexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier];
}
if ([currentCategory isEqualToString:@"Projects"])
{
Project *pr=[projectsArray objectAtIndex:indexPath.row];
NSLog(@"Project ID %i, ProjectName %@", pr.ident, pr.projectName);
UILabel *nameLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 20, 200, 100)];
nameLabel.text=pr.projectName;
UIImageView *iv=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 192)];
iv.image=pr.baseImage;
[cell addSubview:iv];
[cell addSubview:nameLabel];
}
else if ([currentCategory isEqualToString:@"Glossaire"])
{
Glossaire *gl=[glossaireArray objectAtIndex:indexPath.row];
UILabel *nameLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 45)];
nameLabel.font=[UIFont fontWithName:@"Arial" size:25.0f];
nameLabel.text=gl.glossaireName;
nameLabel.backgroundColor=[UIColor redColor];
UILabel *introLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 50, 200, 50)];
introLabel.font=[UIFont fontWithName:@"Arial" size:16.0f];
introLabel.text=gl.intro;
introLabel.backgroundColor=[UIColor redColor];
UILabel *descriptionLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 100, 350, 100)];
descriptionLabel.font=[UIFont fontWithName:@"Arial" size:16.0f];
descriptionLabel.text=gl.description;
descriptionLabel.backgroundColor=[UIColor redColor];
NSLog(@"Glossaire ID: %i, NAME: %@ INTRO: %@ Description %@", gl.ident, gl.glossaireName, gl.intro, gl.description);
[cell addSubview:nameLabel];
[cell addSubview:introLabel];
[cell addSubview:descriptionLabel];
}
return cell;
}
//And switching between categories
- (IBAction)viewProjects:(id)sender
{
currentCategory=@"Projects";
projectsArray=[dbm fetchProjectsSummary];
[mainTable reloadData];
}
- (IBAction)viewGlossaire:(id)sender
{
currentCategory=@"Glossaire";
glossaireArray=[dbm fetchGlossaireSummary];
[mainTable reloadData];
}
Также они говорят, что идентификатор повторного использования устарел, какая у него новая версия? спасибо!