ios - 带有 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;
}
解决方案
它解决了,我只是用 '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;
}
推荐阅读
- python - 如何在熊猫数据框(python)中分解一列,然后将其堆叠/多索引?
- linux - 用于跨多个环境部署的 Shell 脚本和参数文件
- python - 无论如何,用pyfiglet制作的文本居中吗?
- unit-testing - 如何为 AnyLogic 代理代码配置单元测试?
- ios - 了解并减少 Firebase 使用和计费费用
- php - 通过使用 Eloquent 关系查找两个连接之外的 ID 来获取结果
- generics - 无法从返回受约束的泛型类型的函数返回函数
- cuda - 进行多次添加时如何理解并行减少的步幅大小?
- google-apps-script - Grouping rows by day and month. Error by month between days 9 and 10 on every month
- c# - WebGL 为什么要渲染灰度纹理?