Ios 如何在屏幕上来回滚动时保留UITableViewCell的选定状态
我在UITableView中有自定义UITableViewCell单元格。当用户选择一个单元格并将该单元格从屏幕上滚下,然后再滚回屏幕时,所选单元格为空白 我知道在重复使用单元格时,我需要设置单元格中的所有值,但我还没有弄明白这一点 Iamge 1表示用户选择单元格: 图2表示单元格从屏幕上滚动到屏幕上的时间 (忽略图像模糊的事实,只是保护我的客户数据) 注意:我希望能够选择表格,但不建议删除突出显示单元格的功能。实际上,我希望在将所选单元格滚动回屏幕时能够看到蓝色单元格 任何帮助都将不胜感激 编辑:添加一些代码:Ios 如何在屏幕上来回滚动时保留UITableViewCell的选定状态,ios,uitableview,Ios,Uitableview,我在UITableView中有自定义UITableViewCell单元格。当用户选择一个单元格并将该单元格从屏幕上滚下,然后再滚回屏幕时,所选单元格为空白 我知道在重复使用单元格时,我需要设置单元格中的所有值,但我还没有弄明白这一点 Iamge 1表示用户选择单元格: 图2表示单元格从屏幕上滚动到屏幕上的时间 (忽略图像模糊的事实,只是保护我的客户数据) 注意:我希望能够选择表格,但不建议删除突出显示单元格的功能。实际上,我希望在将所选单元格滚动回屏幕时能够看到蓝色单元格 任何帮助都将不胜感
// Define a property to keep track of the cell that was selected last using the NSIndexPath
@property (nonatomic, strong) NSIndexPath *lastSelectedIndexPath;
///////
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Keeps track of the lastest selected entry
self.lastSelectedIndexPath = indexPath;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
IPCSearchResultTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
[self configureCell:cell atIndexPath:indexPath];
return cell;
}
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
// Cast the cell to the custom cell
IPCSearchResultTableViewCell *searchResultCell = (IPCSearchResultTableViewCell *)cell;
// RepositoryIndex is a coredata object with information
MyCoreDataEntity *entity = [self.fetchedResultsController objectAtIndexPath:indexPath];
searchResultCell.label1.text = entity.attribute1;
searchResultCell.label2.text = entity.attribute2;
searchResultCell.label3.text = entity.attribute3;
searchResultCell.label4.text = entity.attribute4;
}
*注意:上面的代码现在似乎正在运行。我不再遇到此问题,也不知道为什么*您尝试过维护(选定单元格的)索引路径数组吗
然后在cellForRowAtIndexPath方法中,如果indexPath在数组中,则设置[cell setSelected:]方法。能否发布一些代码?它可能与
cellforrowatinexpath
有关。我也选择了rowatinexpath,这正是我所做的。