J'ai un problème avec ma tableview. Laissez-moi d'abord esquisser la situation. J'ai une vue avec sur le dessus 2 buttons
(Calendrier et classement). En dessous de ces deux boutons, j'ai une vue de table. Lorsque j'appuie sur un bouton, je règle le tableview's tag (1 or 2)
et je recharge les données du tableau.problème avec une tableview avec différentes étiquettes de tableview
Dans mon classement, je crée une couleur de texte pour une cellule spécifique en bleu. Mais quand je me rafraîchis, les textes d'autres cellules deviennent bleus.
Maintenant pour mon cellForRowAtIndex
J'ai beaucoup de code. Parce que je ne sais pas exactement où le problème est, je vais poster tout le code ici. J'espère que tu ne déranges pas.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//standard cell
static NSString *simpleTableIdentifier = @"KalenderCell";
KalenderCell *cell = (KalenderCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if ((cell == nil) || (![cell isKindOfClass:KalenderCell.class]))
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"KalenderCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
//Cells for button 2
if(self.tableView.tag == 2){
static NSString *simpleTableIdentifier = @"KlassementCell";
KlassementCell *cell = (KlassementCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if ((cell == nil) || (![cell isKindOfClass: KlassementCell.class]))
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"KlassementCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
Klassement *klassement = [self.fetchedResultsController objectAtIndexPath:indexPath];
NSData *dataIcon = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:klassement.icon]];
UIImage *imgIcon = [UIImage imageWithData:dataIcon];
cell.lblPosition.text = klassement.position;
cell.lblName.text = klassement.name;
cell.lblgamesPlayed.text = klassement.gamesPlayed;
cell.lblGamesWon.text = klassement.gamesWon;
cell.lblGamesTied.text = klassement.gamesTied;
cell.lblGamesLost.text = klassement.gamesLost;
cell.lblGoalsPos.text = klassement.goalsPos;
cell.lblGoalsNeg.text = klassement.goalsNeg;
cell.lblGoalsDiff.text = [NSString stringWithFormat:@"%@", klassement.goalsDiff];
cell.lblPoints.text = klassement.points;
cell.imgClub.image = imgIcon;
if([klassement.name isEqualToString:@"KRC Genk"]){
cell.lblPosition.textColor = [UIColor colorWithRed:(56/255.0) green:(119/255.0) blue:(189/255.0) alpha:100] ;
cell.lblName.textColor = [UIColor colorWithRed:(56/255.0) green:(119/255.0) blue:(189/255.0) alpha:100] ;
cell.lblgamesPlayed.textColor = [UIColor colorWithRed:(56/255.0) green:(119/255.0) blue:(189/255.0) alpha:100] ;
cell.lblGamesTied.textColor = [UIColor colorWithRed:(56/255.0) green:(119/255.0) blue:(189/255.0) alpha:100] ;
cell.lblGamesLost.textColor = [UIColor colorWithRed:(56/255.0) green:(119/255.0) blue:(189/255.0) alpha:100] ;
cell.lblGoalsDiff.textColor = [UIColor colorWithRed:(56/255.0) green:(119/255.0) blue:(189/255.0) alpha:100] ;
cell.lblGoalsNeg.textColor = [UIColor colorWithRed:(56/255.0) green:(119/255.0) blue:(189/255.0) alpha:100] ;
cell.lblGoalsPos.textColor = [UIColor colorWithRed:(56/255.0) green:(119/255.0) blue:(189/255.0) alpha:100] ;
cell.lblPoints.textColor = [UIColor colorWithRed:(56/255.0) green:(119/255.0) blue:(189/255.0) alpha:100] ;
cell.lblGamesWon.textColor = [UIColor colorWithRed:(56/255.0) green:(119/255.0) blue:(189/255.0) alpha:100] ;
return cell;
}
return cell;
//Cells for button 1
}else if(self.tableView.tag == 1){
static NSString *simpleTableIdentifier = @"KalenderCell";
KalenderCell *cell = (KalenderCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if ((cell == nil) || (![cell isKindOfClass:KalenderCell.class]))
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"KalenderCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
Kalender *kalender = [self.fetchedResultsController objectAtIndexPath:indexPath];
NSData *imgDataHome = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:kalender.homeIcon]];
NSData *imgDataAway = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:kalender.awayIcon]];
UIImage *imgHome = [UIImage imageWithData:imgDataHome];
UIImage *imgAway = [UIImage imageWithData:imgDataAway];
// Then configure the cell using it ...
if([kalender.type isEqualToString:@"JPL"]){
_imgType = [UIImage imageNamed:@"jupiler.png"];
}else if ([kalender.type isEqualToString:@"EU"]){
_imgType = [UIImage imageNamed:@"europa.jpg"];
}else {
_imgType = nil;
}
cell.lblHome.text = kalender.home;
cell.lblHomeScore.text = kalender.homeScore;
cell.lblAwayScore.text = kalender.awayScore;
cell.lblAway.text = kalender.away;
cell.lblDate.text = kalender.date_text;
cell.lblHour.text = kalender.hour;
cell.img_Home.image = imgHome;
cell.img_Away.image = imgAway;
cell.img_type.image = _imgType;
return cell;
}
return cell;
}
Un autre problème est que parfois les cellules sont elle-même à l'intérieur du double emploi tableview pour 2 ou 3 fois, mais quand je rafraîchis qu'ils tableView est de retour sur OK.
Je sais que c'est beaucoup de code. Mais j'espère que tu veux m'aider!
Cordialement, et merci d'avance!
écran avec le problème
enlèverait juste tous les sous-vues de votre cellule chaque fois que vous chargez la cellule en utilisant dequeueReusableCellWithIdentifier. Cela fonctionne vraiment pour moi. Essayez ma réponse ci-dessous. –