我之前完成了这项工作,但无法再次使用它。无论如何,在我的模型类中,我基本上有一个包含两个排序项目的字典,并且我只希望一个值为YES,其他值为NO。我想要选择UITableViewCell中的项目来反映并选择和取消选择动画。因此,在模型类,我有这样的方法,只是改变了被选定为false,其他值:UITableView didSelectRowForIndexPath,不是动画选择和取消勾选选中标记
- (void)setSingleSort:(NSString *)key {
for (NSString *str in [_sortOrderDictionary allKeys]) {
if (str != key) {
[_sortOrderDictionary setObject:[NSNumber numberWithBool:NO] forKey:str];
}
}
}
然后,我有这个片段在我didSelectRowForIndexPath方法:
NSUInteger row = [indexPath row];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryCheckmark;
[cell setSelected:YES animated:YES];
NSString *key;
BOOL valueAtKey;
key = [_sortCategoryList objectAtIndex:row];
valueAtKey = [[dmgr.SortOrderDictionary valueForKey:key] boolValue];
if (valueAtKey != YES) {
[dmgr.SortOrderDictionary setObject:[NSNumber numberWithBool:!valueAtKey] forKey:key];
[dmgr setSingleSort:key];
UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:_lastIndexPath];
oldCell.accessoryType = UITableViewCellAccessoryNone;
[tableView deselectRowAtIndexPath:_lastIndexPath animated:YES];
}
_lastIndexPath = indexPath;
[tableView reloadData]; //Edited, added this to the end and it seems to work. Don't know why it's needed though since the deslectRowAtIndexPath should animated, along with the setSelected:Animated: right?
无赖,没有工作 – Crystal