文字列を追加してから、以前に行ったすべての選択を維持したまま、追加された行を選択する必要があります。
アーキテクチャの問題により、 を呼び出す必要がありますrefreshSelections
。これは、最初に選択を解除し、その後に 2 回選択します。
実際、行を追加した後、すべての選択が点滅し、追加された行のみが選択されます。別の行を追加すると、すべての古い選択が再び点滅し、新しい行が選択されたままになります。
しかし、最初の後に任意の場所にブレークポイントを設定すると、問題refreshSelections
なく動作します。
同時実行の問題だと思いますが、解決方法がわかりません。
// This is called
-(void)addString:(NSString *)text
{
stringsList = [stringsList arrayByAddingObject:text];
[self applyFilter:self.searchBar.text];
// Any breakpoint after will help
[filterSelect addStringToSelected:text];
}
- (void)applyFilter:(NSString *)filterString
{
[filterSelect reloadData:YES];
}
- (void)refreshSelections
{
for (NSUInteger row = 0; row < stringsList.count; ++row) {
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:row inSection:0];
[stringsTableView deselectRowAtIndexPath:indexPath animated:NO];
}
NSIndexSet *selectedIndexes = [stringsList indexesOfObjectsPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
return [selectedStrings containsObject:obj];
}];
[selectedIndexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
[stringsTableView selectRowAtIndexPath:[NSIndexPath indexPathForItem:idx inSection:0] animated:NO scrollPosition:UITableViewScrollPositionNone];
}];
}
- (void)reloadData:(BOOL)saveOrder
{
stringsList = [self.dataSource stringsToDisplayInMultipleStringsSelect:self];
[stringsTableView reloadData];
[self refreshSelections];
}
- (void)addStringToSelected:(NSString *)string
{
[self storeSelectedString:string];
[self refreshSelections:1];
}
私のWATのすべて。