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

时间:2014-10-01 06:57:06

标签: ios objective-c iphone uitableview

对于练习我正在显示/隐藏Android中的 UITableView 中的值,如 MXPlayer 。 当我添加该值时,它应该在我为自定义单元格制作的标签中显示 NEW 。一旦我读取了该值,它将显示在下一个视图中,然后返回列表视图,其显示正确,因为我除外,但如果我点击另一个值,它将更改以前的值。

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

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

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

1 个答案:

答案 0 :(得分:1)

再次简单的错误你给同一个名字所以它出错了所以你需要将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];
}