作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 tableview 并且正在对 uitableview 进行多次检查。一切都很完美,我'获得了正确的值,但是当我滚动 TableView 时,它丢失了复选标记图像(使用默认复选标记,没有自定义图像),但所选值保留在数组中...
滚动表格 View 会删除复选标记图像。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
AppDelegate *app= (AppDelegate *)[[UIApplication sharedApplication]delegate];
if([_tableView cellForRowAtIndexPath:indexPath].accessoryType == UITableViewCellAccessoryCheckmark){
NSLog(@"yes");
[placesvisitedarray removeObject:[app.nameArray objectAtIndex:indexPath.row]];
[_tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryNone;
}
else
{
NSLog(@"no");
[_tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
[placesvisitedarray addObject:[app.nameArray objectAtIndex:indexPath.row]];
}
// [_tableView reloadData];
}
最佳答案
复选标记已被删除,因为当您滚动表格 View 时,将调用 cellForRowAtIndexPath:
并重新创建单元格。
您可以编写一个方法来检查数组中是否存在某个值:
- (BOOL)stringExistsInPlacesVisited:(NSString *)stringToMatch {
for (NSString string in placesvisitedarray) {
if ([string isEqualTo:stringToMatch])
return YES;
}
return NO;
}
然后在cellForRowAtIndexPath:
中,您必须检查placesvisitedarray并插入/删除复选标记。
if ([stringExistsInPlacesVisited:[app.nameArray objectAtIndex:indexPath.row])
cell.accessoryType = UITableViewCellAccessoryCheckmark;
else
cell.accessoryType = UITableViewCellAccessoryNone;
代码未经测试,因此可能无法工作,但至少它会让您了解如何继续。
关于ios - 滚动 tableview 会删除 uitableview 单元格中的复选标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14797316/
我是一名优秀的程序员,十分优秀!