When I try to set the accessory view of a table view cell to a custom type image and run it in the simulator, I see that multiple cells have the accessory view image instead of the one that is currently selected. But when I set the accessory view to "cell.accessoryType = UITableViewCellAccessoryCheckmark;", I don't have this problem. Here is the code.
id item = [_items objectAtIndex:row];
if ([_currentVale isKindOfClass:[NSString class]])
{
if ([item isEqualToString:_currentVale])
{
UIImageView *checkmark = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"checkmark-outline.png"]];
checkmark.frame = CGRectMake(0, 0, 20, 20);
cell.accessoryView = checkmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
}
else if ([_currentVale isKindOfClass:[NSNumber class]])
{
if ([item isEqualToNumber:_currentVale])
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
}
Two images of what I'm talking about. Only one value should be chosen in the picker but there is two showing the checkmark
答案 0 :(得分:1)
细胞正在重复使用。您还需要在其他内部将附件视图设置为nil。
npm version
答案 1 :(得分:0)
在单元格中,您不想显示图像,不要忘记设置
func deleteThisFile(fileToDelete: String) {
let tempLocalDir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first
do {
let directoryContents = try FileManager.default.contentsOfDirectory(at: tempLocalDir!, includingPropertiesForKeys: nil, options: [])
let tempList = directoryContents.filter{ $0.absoluteString.contains(fileToDelete) }
//tried these things:
try FileManager.removeItem(tempList.first) // Argument labels '(_:)' do not match any available overloads
/*
* try FileManager.removeItem(at: tempList.first!) // Ambiguous reference to member 'removeItem(atPath:)'
*
* try FileManager.removeItem(atPath: (tempList.first?.absoluteString)!) // Ambiguous reference to member 'removeItem(atPath:)'
*/
} catch let error as NSError {
print(error.localizedDescription)
}
}