Iphone 具有不同tableview标记的tableview出现问题
我的tableview有问题。让我先概述一下情况。我有一个视图,上面有两个按钮(日历和排名)。在这两个按钮下面,我有一个tableview。当我按下按钮时,我设置了Iphone 具有不同tableview标记的tableview出现问题,iphone,objective-c,ios,uitableview,Iphone,Objective C,Ios,Uitableview,我的tableview有问题。让我先概述一下情况。我有一个视图,上面有两个按钮(日历和排名)。在这两个按钮下面,我有一个tableview。当我按下按钮时,我设置了tableview的标签(1或2),然后重新加载tableview的数据 在我的排名中,我将一个特定单元格的文本颜色设置为蓝色。但当我刷新时,其他手机的短信会变成蓝色 现在对于我的cellforrowatinex我有很多代码。因为我不知道问题出在哪里,所以我会把所有的代码都贴在这里。我希望你不要麻烦 - (UITableViewCel
tableview的标签(1或2)
,然后重新加载tableview的数据
在我的排名中,我将一个特定单元格的文本颜色设置为蓝色。但当我刷新时,其他手机的短信会变成蓝色
现在对于我的cellforrowatinex
我有很多代码。因为我不知道问题出在哪里,所以我会把所有的代码都贴在这里。我希望你不要麻烦
- (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;
}
另一个问题是,有时单元格在tableview中复制自身2到3次,但当我刷新它们时,tableview恢复正常
我知道这是很多代码。但我希望你能帮助我
致以亲切的问候,并在此表示衷心的感谢
出现问题的屏幕
在以下条件下,您可以设置蓝色
if([klassement.name isEqualToString:@"KRC Genk"]){
/// set blue color
}
因为它是添加黑色的其他部分
像贝娄一样
else{
cell.lblPosition.textColor = [UIColor blackColor] ;
cell.lblName.textColor = [UIColor blackColor] ;
cell.lblgamesPlayed.textColor = [UIColor blackColor] ;
cell.lblGamesTied.textColor = [UIColor blackColor] ;
cell.lblGamesLost.textColor = [UIColor blackColor] ;
cell.lblGoalsDiff.textColor = [UIColor blackColor] ;
cell.lblGoalsNeg.textColor = [UIColor blackColor] ;
cell.lblGoalsPos.textColor = [UIColor blackColor] ;
cell.lblPoints.textColor = [UIColor blackColor] ;
cell.lblGamesWon.textColor = [UIColor blackColor] ;
return cell;
}
在以下条件下,设置蓝色
if([klassement.name isEqualToString:@"KRC Genk"]){
/// set blue color
}
因为它是添加黑色的其他部分
像贝娄一样
else{
cell.lblPosition.textColor = [UIColor blackColor] ;
cell.lblName.textColor = [UIColor blackColor] ;
cell.lblgamesPlayed.textColor = [UIColor blackColor] ;
cell.lblGamesTied.textColor = [UIColor blackColor] ;
cell.lblGamesLost.textColor = [UIColor blackColor] ;
cell.lblGoalsDiff.textColor = [UIColor blackColor] ;
cell.lblGoalsNeg.textColor = [UIColor blackColor] ;
cell.lblGoalsPos.textColor = [UIColor blackColor] ;
cell.lblPoints.textColor = [UIColor blackColor] ;
cell.lblGamesWon.textColor = [UIColor blackColor] ;
return cell;
}
在创建新单元格的else部分添加以下行:
[cell.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
你可以看到我的答案
试试这个:
if ((cell == nil) || (![cell isKindOfClass:KalenderCell.class]))
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"KalenderCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
else
{
[cell.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
}
在创建新单元格的else部分添加以下行:
[cell.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
你可以看到我的答案
试试这个:
if ((cell == nil) || (![cell isKindOfClass:KalenderCell.class]))
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"KalenderCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
else
{
[cell.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
}
我告诉问题是当你滚动tableview时,你的单元格在另一个单元格中变为蓝色,对吗?不,我的tableview上有一个下拉刷新功能。调用时,我清空tableview的数据,然后重新加载它。当它重新加载时。除de'KRC GENK'单元格外的其他单元格为蓝色。当您单击排名按钮时,重新加载数据意味着tableview??不,我下拉刷新,就像您可以在twitter应用程序中刷新推文一样。我添加了一个带有问题的屏幕,希望您现在理解我的问题。提前谢谢你,伙计!我告诉问题是当你滚动tableview时,你的单元格在另一个单元格中变为蓝色,对吗?不,我的tableview上有一个下拉刷新功能。调用时,我清空tableview的数据,然后重新加载它。当它重新加载时。除de'KRC GENK'单元格外的其他单元格为蓝色。当您单击排名按钮时,重新加载数据意味着tableview??不,我下拉刷新,就像您可以在twitter应用程序中刷新推文一样。我添加了一个带有问题的屏幕,希望您现在理解我的问题。提前谢谢你,伙计!每次使用dequeueReusableCellWithIdentifier加载单元格时,只需删除单元格的所有子视图。这对我真的很有用。请尝试下面的答案。每次使用dequeueReusableCellWithIdentifier加载单元格时,只需删除单元格的所有子视图。这对我真的很有用。试试下面我的答案。