在iOS7的UITableView中显示/隐藏新值?
为了练习,我正在做的是在UITableView中显示/隐藏值,就像android中的MXPlayer一样。 当我添加值时,它应该在我为自定义单元格制作的标签中显示NEW。一旦我读取了该值,它将显示在下一个视图中,然后返回到列表视图,它将显示正确的值,但如果我单击另一个值,它将更改以前的值 这段代码我已经试过了..帮帮我在iOS7的UITableView中显示/隐藏新值?,ios,objective-c,iphone,uitableview,Ios,Objective C,Iphone,Uitableview,为了练习,我正在做的是在UITableView中显示/隐藏值,就像android中的MXPlayer一样。 当我添加值时,它应该在我为自定义单元格制作的标签中显示NEW。一旦我读取了该值,它将显示在下一个视图中,然后返回到列表视图,它将显示正确的值,但如果我单击另一个值,它将更改以前的值 这段代码我已经试过了..帮帮我 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPat
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *Identifier = @"ceelll";
customCell *cell =(customCell *) [tableView dequeueReusableCellWithIdentifier:Identifier];
if (cell==nil) {
cell=[[[NSBundle mainBundle]loadNibNamed:@"customCell" owner:self options:nil]objectAtIndex:0];
}
cell.dataLbl.text=self.listData[indexPath.row];
if([self.checkedData isEqual:indexPath])
{
cell.NewHideLbl.text=@"VIEW";
cell.NewHideLbl.textColor=[UIColor greenColor];
}
else
{
cell.NewHideLbl.text=@"NEW";
cell.NewHideLbl.textColor=[UIColor redColor];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(self.checkedData)
{
customCell* cell =(customCell*) [tableView cellForRowAtIndexPath:self.checkedData];
cell.NewHideLbl.text=@"NEW";
cell.NewHideLbl.textColor=[UIColor redColor];
}
if([self.checkedData isEqual:indexPath])
{
self.checkedData = nil;
}
else
{
customCell* cell =(customCell*) [tableView
cellForRowAtIndexPath:indexPath];
cell.NewHideLbl.text=@"VIEW";
cell.NewHideLbl.textColor=[UIColor greenColor];
self.checkedData = indexPath;
}
self.detailObj.tempStr=self.listData[indexPath.row];
[self.navigationController pushViewController:self.detailObj animated:YES];
}
这仅用于学习目的..帮助我提前感谢..简单的错误再次说明您使用了相同的名称,因此可能是错误的,因此您需要将“新建”更改为“查看”
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(self.checkedData)
{
customCell* cell =(customCell*) [tableView cellForRowAtIndexPath:self.checkedData];
// cell.NewHideLbl.text=@"NEW"; here again you are assigning label NEW so its getting new one
cell.NewHideLbl.text=@"VIEW";
cell.NewHideLbl.textColor=[UIColor greenColor];
}
if([self.checkedData isEqual:indexPath])
{
self.checkedData = nil;
}
else
{
customCell* cell =(customCell*) [tableView
cellForRowAtIndexPath:indexPath];
cell.NewHideLbl.text=@"VIEW";
cell.NewHideLbl.textColor=[UIColor greenColor];
self.checkedData = indexPath;
}
self.detailObj.tempStr=self.listData[indexPath.row];
[self.navigationController pushViewController:self.detailObj animated:YES];
}