gpt4 book ai didi

ios - 在 iOS7 的 UITableView 中显示/隐藏新值?

转载 作者:行者123 更新时间:2023-11-29 12:36:41 26 4
gpt4 key购买 nike

为了练习,我正在显示/隐藏 UITableView 中的值,就像 android 中的 MXPlayer 一样。当我添加值时,它应该在我为自定义单元格制作的标签中显示 NEW 。一旦我读取了该值,它将显示在下一个 View 中,然后返回到 ListView ,它的显示正确如我所料,但如果我单击另一个值,它将更改以前的值。

到目前为止我已经尝试过这段代码..帮助我

- (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];
}

这仅用于学习目的..提前帮助我谢谢..

最佳答案

又犯了一个简单的错误,你给了同样的名字,所以它出错了,所以你需要把 NEW 改成 VIEW

- (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];
}

关于ios - 在 iOS7 的 UITableView 中显示/隐藏新值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26135731/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com