首页 > 解决方案 > 带有 UILabel 内容的 UITableViewCell 在滚动时发生变化

问题描述

请检查下面的代码和图像以了解,

我用于UITableView配置文件编辑,每个单元格都包含UILabel旧数据。输入新的详细信息并自动滚动后,值是对旧数据的更改。

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return identifiersAry.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    EditProfileTableViewCell *cell = (EditProfileTableViewCell *)[tableView dequeueReusableCellWithIdentifier:[identifiersAry objectAtIndex:indexPath.row]];

    switch (indexPath.row) {

        case NAME_CELL:
            nameTxtFld = cell.firstNameTxtLbl;
            name = [[[NSUserDefaults standardUserDefaults] objectForKey:@"user"] objectForKey:@"name"];
            cell.firstNameTxtLbl.text = [[[NSUserDefaults standardUserDefaults] objectForKey:@"user"] objectForKey:@"name"];
            break;

        case UserName_Cell:
            userNameTxtFld = cell.userNameTxtFld;
            cell.userNameTxtFld.text = [[[NSUserDefaults standardUserDefaults] objectForKey:@"user"] objectForKey:@"userName"];            
            break;

        default:
            break;
   }

   [cell setSelectionStyle:UITableViewCellSelectionStyleNone];

   return cell;
}

在此处输入图像描述

标签: iosobjective-cuitableview

解决方案


它解决了,我只是用 'YES' 获取初始布尔值,当它第一次加载从 NSUserDefaults 存储的所有数据时,当加载最后一个单元格时,我只是更改 'NO' 值然后它为我工作谢谢。

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return identifiersAry.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    EditProfileTableViewCell *cell = (EditProfileTableViewCell *)[tableView dequeueReusableCellWithIdentifier:[identifiersAry objectAtIndex:indexPath.row]];

    switch (indexPath.row) {

        case NAME_CELL:
            nameTxtFld = cell.firstNameTxtLbl;
            name = [[[NSUserDefaults standardUserDefaults] objectForKey:@"user"] objectForKey:@"name"];
            if (isEnteringFirstTime)
            cell.firstNameTxtLbl.text = [[[NSUserDefaults standardUserDefaults] objectForKey:@"user"] objectForKey:@"name"];
            break;

        case UserName_Cell:
            userNameTxtFld = cell.userNameTxtFld;
            if (isEnteringFirstTime)
            cell.userNameTxtFld.text = [[[NSUserDefaults standardUserDefaults] objectForKey:@"user"] objectForKey:@"userName"];  
           isEnteringFirstTime = NO;
            break;

        default:
            break;
    }

    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];

    return cell;
}

推荐阅读