I have a UIcollectionView to display data I receive from a bluetooth peripheral
I get new data every second.
for re-ordering I found this function
override func collectionView(_ collectionView: UICollectionView,
moveItemAt sourceIndexPath: IndexPath,
to destinationIndexPath: IndexPath)
it work but only if I move for one position
because I reload data every second, if the reload occur during a move, the move is reset
If I stop the reload of data, it work well like a normal re-ordering
But to stop data updating, I need to know when the Drag Begin to stop new data from coming in
and when the Drag ended to restart the data.
Is there a way to know it without implementing the whole UICollectionViewDragDelegate, UICollectionViewDropDelegate
Because I am having problem doing that :-)
Perhaps this will help. I use a UITableViewController class (so "self" is the table) and it is also a UITextFieldDelegate and I use ObjectiveC.
When the user indicates they want to move a cell I do this:
self.title=@"Reorder Stocks";(note that this is a gross violation of MVC - I am storing a C variable in a V element. "I can easier teach twenty what were good to be done then be one of the twenty to follow mine own teaching." (Wm. Shakespeare, The Merchant of Venice)
I have the following functions:
-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)indexPathFrom toIndexPath:(NSIndexPath *)indexPathTo{
NSMutableDictionary *temp= [[NSMutableDictionary alloc] initWithDictionary:[theStocks objectAtIndex:[indexPathFrom row]]] ;
[theStocks removeObjectAtIndex:[indexPathFrom row]];
[theStocks insertObject:temp atIndex:[indexPathTo row]];
[tableView reloadData];
// and here you would again allow reloading of the incoming data.
}
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath{
if([self.title isEqualToString:@"Reorder Stocks"]){
// here you would set some variable to stop reloading
return YES;
}else{
return NO;
}
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewCellEditingStyleNone;
}