UITalbeView need to delete row that might be reordering - swift

No, my code is not crashing by just deleting content, or reordering content, that works fine.
The issue is, the content is connected to a pusher service and it might need to delete a row at any point, even while reordering. I have been looking around for some time and I haven't found a way to:
Cancel the reordering of the cell when delete is needed (it goes
blank / clear).
Avoid any actions from a deleted cell when it finishes
'reordering'.
Tell if the table is reordering the cell before I need to
delete it.
So in short I need to delete a cell that might be reordering from a UITableView.
Have you faced a similar issue?

Anyways, I found a way to do it. Here's the logic just in case anyone ever needs it.
Prevent the cell's movement with the use of tableView:targetIndexPathForMoveFromRowAt:
On delete control don't call [yourTableView].deleteRows, call reloadData
Looks like that's it.
Thanks

Related

Is there a way to reduce the time taken (long press) to initiate the drag of a collection view cell?

I've implemented drag and drop between three collection views using UICollectionViewDragDelegate and UICollectionViewDropDelegate and it seems to be working okay. The only issue is, I don't like the long press that's required to initiate the drag session. I can't find anything in the docs explaining how to override this behaviour so was wondering if one of you fine folks could help me out?
I can see a solution proposed by julsh in the following question - Ability to shorten UIDragInteraction's long press timing - which looks great... But I don't know how to implement it against a collection view cell?
If anyone has any ideas I'd really appreciate the help.
I found this which should help. I ran into the same problem and it turns out that the UICollectionView holds the gesture recognizers.

RXSwift Update single element

Considering I have a array of items which might be updated on a different view controller and get notified update the change.
How can I update a Observable<[SomeObject]> with a single SomeObject modification so the change will then be propagated to the UITableViewController that presets these items?
P.S.
I can load the whole thing again with some hack, but it's obviously wrong for various reasons.
Thanks.
The short answer is, you can't.
However, if you change your model, there are several ways you can go about doing it. One example is here: https://github.com/dtartaglia/RxMultiCounter
In RxMultiCounter, I populate the tableView with an Observable<[UUID]> and track the changes for each item inside an Observable<[UUID: SomeObject]>. Updating the latter observable doesn't cause the tableView to reload.

NSCollectionView error: Parameter indexPath out of bounds or nil

I've recently been playing around with OSX programming (usually an iOS guy) but I've hit a strange issue with NSCollectionView that I just can't seem to debug.
When I change the data that my data source uses to populate the collection with items, I call reloadData() on the collection view as usual and sometimes hits an assertion. The error I get is Parameter indexPath out of bounds or nil. If I don't change the data the app always crashes at the same point(s) though sometimes, usually the first time, it works just fine and only crashes subsequently.
Now, I've debugged this numerous times. The data is correct and at no point in my code do I ever see a nil index path. The assertion always occurs on the makeItemWithIdentifier call, and always on the last item in the collection. If I continue, I either see what I expect or else some of the cells from the previous collection are still there behind the new cells.
At one point I refactored the code slightly and found the error occurring in NSCollectionViews itemAtIndexPath: function instead.
Has anyone else seen this error and, if so, what caused it?
Update 2: I now know what is causing this issue, but have no idea how to prevent it. What happens is this: the user clicks an item in the collection view. That item changes the data object that the data source is reading from calls reloadData during the collection view delegate's didSelectItemsAtIndexPaths method. For some reason, after execution of this method, the collection view is queried again for the cell with that index path. If the table has been reloaded in the meantime then that cell is gone, leading to the exception. In short: you can't call 'reload' on a collection view while a mouse event is being processed on one of its cells without getting an annoying assertion. So if anyone can think of a way around this issue, I'd love to hear it!

Custom PickerView froze up (With sample project)

Background: I have been wanting a PickerView that is exactly matches that of Safari. I looked through many Gits and found none that work quite as exactly. I decided to build my own. It is complete now, but there is a bug that would not go away.
Problem: If you run the sample project you will be greeted with 2 text fields.
Tap on one of the textfields - it brings up the BTPickerView. Everything works just as you would expect.
Choose the fourth choice, then press done.
Tap on the same textfield. This time, the debug log will show you that you have executed an infinite loop, which freezes the app.
Question: What did I do to cause it? And how do I fix it?
I have tried everything to boil it down. It comes down to this and I could not go any further. Please advise.
Edit: Here is the sample code you can download in case anyone missed the blue link above.
The issue seems to be with the constraints in BTPickerLabel. If you temporarily disable the constraints from BTPickerLabel, code works fine. Enforcing constraint might trigger the reloading of entire picker view infinitely. I hope it should help you to fix the problem.

Is it advisable to write to a plist from a UITableView didSelectRowAtIndexPath:?

I have a UITableView and am wondering if it's advisable to write to a plist file after a user selects a row in a table. Basically the user selects a row (or many) and then touches an APPLY button and the plist would be updated recording which rows have been selected by the user.
thanks for any help or advice
Yes, You can do this.
I don't think there's any problem with this.
However, make sure you don't overwrite it. As in clear it first and write it. Or, it might cause a conflict in your logic.